forked from sabre-io/Baikal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompliancePlugin.php
More file actions
81 lines (65 loc) · 2.59 KB
/
Copy pathCompliancePlugin.php
File metadata and controls
81 lines (65 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
//see https://sabre.io/dav/writing-plugins/
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
//use Sabre\HTTP\RequestInterface;
//use Sabre\HTTP\ResponseInterface;
use Sabre\VObject;
require_once("settingsHydrogen.php");
require_once("Hydrogen/clsDateTimeExt.php");
require_once("Hydrogen/lib/Debug.php");
//require_once("Hydrogen/db/clsDataSource.php");
/*
The purpose of this plugin is to identify and correct specific client inputs that are either non standard or incomplete.
1. BusyCal client will save "Journal" entries not as VJOURNAL but as VEVENT with attribute "X-BUSYMAC-EVENT-TYPE:JOURNAL" even though it is capable of recognizing VJOURNAL events.
*/
class CompliancePlugin extends ServerPlugin {
protected $server;
private $vobject;
function getName() {
return 'compliance';
}
function initialize(Server $server){
$this->server = $server;
$server->on('beforeWriteContent',[$this,'UpdateHandler' ]);
$server->on('beforeCreateFile',[$this,'CreateHandler' ]);
}
//This function handles new files.
function CreateHandler($path, &$data, \Sabre\DAV\ICollection $parent, &$modified) {
$mod=false;
debug("Compliance plugin incoming file path: " . $path);
if (is_resource($data)) {
$data = stream_get_contents($data);
}
if (strpos($path,"calendars/")!==false &&
strpos($data,"BEGIN:VEVENT")!==false &&
strpos($data,"X-BUSYMAC-EVENT-TYPE:JOURNAL")!==false
) {
debug ("Compliance plugin detects non-compliant BusyCal entry");
$data=str_replace("BEGIN:VEVENT","BEGIN:VJOURNAL",$data);
$data=str_replace("END:VEVENT","END:VJOURNAL",$data);
$mod=true;
}
$modified=$mod;
return true;
}
//This function handles file updates.
function UpdateHandler($path, \Sabre\DAV\IFile $node, &$data, &$modified) {
$mod=false;
if (is_resource($data)) {
$data = stream_get_contents($data);
}
debug("Compliance plugin updating file path: " . $path);
if (strpos($path,"calendars/")!==false &&
strpos($data,"BEGIN:VEVENT")!==false &&
strpos($data,"X-BUSYMAC-EVENT-TYPE:JOURNAL")!==false
) {
debug ("Compliance plugin detects non-compliant BusyCal update");
$data=str_replace("BEGIN:VEVENT","BEGIN:VJOURNAL",$data);
$data=str_replace("END:VEVENT","END:VJOURNAL",$data);
$mod=true;
}
$modified=$mod;
return true;
}
}