ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\CardDAV\VCFExportPlugin Class Reference

VCF Exporter. More...

+ Inheritance diagram for Sabre\CardDAV\VCFExportPlugin:
+ Collaboration diagram for Sabre\CardDAV\VCFExportPlugin:

Public Member Functions

 initialize (DAV\Server $server)
 Initializes the plugin and registers event handlers. More...
 
 httpGet (RequestInterface $request, ResponseInterface $response)
 Intercepts GET requests on addressbook urls ending with ?export. More...
 
 generateVCF (array $nodes)
 Merges all vcard objects, and builds one big vcf export. More...
 
 getPluginName ()
 Returns a plugin name. More...
 
 getPluginInfo ()
 Returns a bunch of meta-data about the plugin. More...
 
- Public Member Functions inherited from Sabre\DAV\ServerPlugin
 initialize (Server $server)
 This initializes the plugin. More...
 
 getFeatures ()
 This method should return a list of server-features. More...
 
 getHTTPMethods ($path)
 Use this method to tell the server this plugin defines additional HTTP methods. More...
 
 getPluginName ()
 Returns a plugin name. More...
 
 getSupportedReportSet ($uri)
 Returns a list of reports this plugin supports. More...
 
 getPluginInfo ()
 Returns a bunch of meta-data about the plugin. More...
 

Protected Attributes

 $server
 

Detailed Description

VCF Exporter.

This plugin adds the ability to export entire address books as .vcf files. This is useful for clients that don't support CardDAV yet. They often do support vcf files.

Author
Evert Pot (http://evertpot.com/)
Thomas Tanghus (http://tanghus.net/) http://sabre.io/license/ Modified BSD License

Definition at line 22 of file VCFExportPlugin.php.

Member Function Documentation

◆ generateVCF()

Sabre\CardDAV\VCFExportPlugin::generateVCF ( array  $nodes)

Merges all vcard objects, and builds one big vcf export.

Parameters
array$nodes
Returns
string

Definition at line 113 of file VCFExportPlugin.php.

References Sabre\VObject\$output, Sabre\CardDAV\Plugin\NS_CARDDAV, and Sabre\VObject\Reader\read().

Referenced by Sabre\CardDAV\VCFExportPlugin\httpGet().

113  {
114 
115  $output = "";
116 
117  foreach ($nodes as $node) {
118 
119  if (!isset($node[200]['{' . Plugin::NS_CARDDAV . '}address-data'])) {
120  continue;
121  }
122  $nodeData = $node[200]['{' . Plugin::NS_CARDDAV . '}address-data'];
123 
124  // Parsing this node so VObject can clean up the output.
125  $vcard = VObject\Reader::read($nodeData);
126  $output .= $vcard->serialize();
127 
128  // Destroy circular references to PHP will GC the object.
129  $vcard->destroy();
130 
131  }
132 
133  return $output;
134 
135  }
const NS_CARDDAV
xml namespace for CardDAV elements
Definition: Plugin.php:33
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPluginInfo()

Sabre\CardDAV\VCFExportPlugin::getPluginInfo ( )

Returns a bunch of meta-data about the plugin.

Providing this information is optional, and is mainly displayed by the Browser plugin.

The description key in the returned array may contain html and will not be sanitized.

Returns
array

Definition at line 162 of file VCFExportPlugin.php.

References Sabre\CardDAV\VCFExportPlugin\getPluginName().

162  {
163 
164  return [
165  'name' => $this->getPluginName(),
166  'description' => 'Adds the ability to export CardDAV addressbooks as a single vCard file.',
167  'link' => 'http://sabre.io/dav/vcf-export-plugin/',
168  ];
169 
170  }
getPluginName()
Returns a plugin name.
+ Here is the call graph for this function:

◆ getPluginName()

Sabre\CardDAV\VCFExportPlugin::getPluginName ( )

Returns a plugin name.

Using this name other plugins will be able to access other plugins using ::getPlugin

Returns
string

Definition at line 145 of file VCFExportPlugin.php.

Referenced by Sabre\CardDAV\VCFExportPlugin\getPluginInfo().

145  {
146 
147  return 'vcf-export';
148 
149  }
+ Here is the caller graph for this function:

◆ httpGet()

Sabre\CardDAV\VCFExportPlugin::httpGet ( RequestInterface  $request,
ResponseInterface  $response 
)

Intercepts GET requests on addressbook urls ending with ?export.

Parameters
RequestInterface$request
ResponseInterface$response
Returns
bool

Definition at line 55 of file VCFExportPlugin.php.

References $aclPlugin, $filename, $format, $nodes, Sabre\VObject\$output, $path, Sabre\CardDAV\VCFExportPlugin\generateVCF(), Sabre\HTTP\RequestInterface\getPath(), Sabre\HTTP\RequestInterface\getQueryParameters(), Sabre\CardDAV\Plugin\NS_CARDDAV, Sabre\HTTP\MessageInterface\setBody(), Sabre\HTTP\MessageInterface\setHeader(), and Sabre\HTTP\ResponseInterface\setStatus().

55  {
56 
57  $queryParams = $request->getQueryParameters();
58  if (!array_key_exists('export', $queryParams)) return;
59 
60  $path = $request->getPath();
61 
62  $node = $this->server->tree->getNodeForPath($path);
63 
64  if (!($node instanceof IAddressBook)) return;
65 
66  $this->server->transactionType = 'get-addressbook-export';
67 
68  // Checking ACL, if available.
69  if ($aclPlugin = $this->server->getPlugin('acl')) {
70  $aclPlugin->checkPrivileges($path, '{DAV:}read');
71  }
72 
73  $nodes = $this->server->getPropertiesForPath($path, [
74  '{' . Plugin::NS_CARDDAV . '}address-data',
75  ], 1);
76 
77  $format = 'text/directory';
78 
79  $output = null;
80  $filenameExtension = null;
81 
82  switch ($format) {
83  case 'text/directory':
84  $output = $this->generateVCF($nodes);
85  $filenameExtension = '.vcf';
86  break;
87  }
88 
89  $filename = preg_replace(
90  '/[^a-zA-Z0-9-_ ]/um',
91  '',
92  $node->getName()
93  );
94  $filename .= '-' . date('Y-m-d') . $filenameExtension;
95 
96  $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
97  $response->setHeader('Content-Type', $format);
98 
99  $response->setStatus(200);
100  $response->setBody($output);
101 
102  // Returning false to break the event chain
103  return false;
104 
105  }
$path
Definition: aliased.php:25
$format
Definition: metadata.php:141
foreach($paths as $path) $request
Definition: asyncclient.php:32
const NS_CARDDAV
xml namespace for CardDAV elements
Definition: Plugin.php:33
$filename
Definition: buildRTE.php:89
generateVCF(array $nodes)
Merges all vcard objects, and builds one big vcf export.
$response
$aclPlugin
+ Here is the call graph for this function:

◆ initialize()

Sabre\CardDAV\VCFExportPlugin::initialize ( DAV\Server  $server)

Initializes the plugin and registers event handlers.

Parameters
DAV\Server$server
Returns
void

Definition at line 37 of file VCFExportPlugin.php.

References $path, and Sabre\CardDAV\VCFExportPlugin\$server.

37  {
38 
39  $this->server = $server;
40  $this->server->on('method:GET', [$this, 'httpGet'], 90);
41  $server->on('browserButtonActions', function($path, $node, &$actions) {
42  if ($node instanceof IAddressBook) {
43  $actions .= '<a href="' . htmlspecialchars($path, ENT_QUOTES, 'UTF-8') . '?export"><span class="oi" data-glyph="book"></span></a>';
44  }
45  });
46  }
$path
Definition: aliased.php:25

Field Documentation

◆ $server

Sabre\CardDAV\VCFExportPlugin::$server
protected

Definition at line 29 of file VCFExportPlugin.php.

Referenced by Sabre\CardDAV\VCFExportPlugin\initialize().


The documentation for this class was generated from the following file: