File tree 4 files changed +42
-5
lines changed
4 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,16 @@ public function __construct(
32
32
/**
33
33
* {@inheritdoc}
34
34
*/
35
- public function getWopiClientURL (string $ mimetype = 'text/plain ' ): ?string {
36
- $ result = $ this ->parsedXml ->xpath (sprintf ('/wopi-discovery/net-zone/app[@name= \'%s \']/action ' , $ mimetype ));
35
+ public function getWopiClientURL (string $ mimetype = 'text/plain ' , ?bool $ edit = NULL ): ?string {
36
+ $ result = $ this ->parsedXml ->xpath (sprintf (
37
+ '/wopi-discovery/net-zone/app[@name= \'%s \']/action%s ' ,
38
+ $ mimetype ,
39
+ match ($ edit ) {
40
+ TRUE => "[@name='edit'] " ,
41
+ FALSE => "[@name='view'] " ,
42
+ NULL => '' ,
43
+ }
44
+ ));
37
45
if (empty ($ result [0 ]['urlsrc ' ][0 ])) {
38
46
return NULL ;
39
47
}
Original file line number Diff line number Diff line change @@ -25,11 +25,16 @@ interface DiscoveryInterface {
25
25
* @param string $mimetype
26
26
* Mime type for which to get the WOPI client URL.
27
27
* This refers to config entries in the discovery.xml file.
28
+ * @param bool|null $edit
29
+ * TRUE to get the edit url, FALSE to get the view url, NULL to get
30
+ * whichever url comes first, no matter if it has 'view' or 'edit' or none.
31
+ * In Collabora, this parameter makes little difference.
28
32
*
29
33
* @return string|null
30
- * The WOPI client URL, or NULL if none provided for the MIME type.
34
+ * The WOPI client URL, or NULL if none provided for the MIME type and
35
+ * operation.
31
36
*/
32
- public function getWopiClientURL (string $ mimetype = 'text/plain ' ): ?string ;
37
+ public function getWopiClientURL (string $ mimetype = 'text/plain ' , ? bool $ edit = NULL ): ?string ;
33
38
34
39
/**
35
40
* Gets the public key used for proofing.
Original file line number Diff line number Diff line change 7
7
<app name =" text/csv" >
8
8
<action default =" true" ext =" " name =" edit" urlsrc =" http://csv.collabora.test:9980/browser/61cf2b4/cool.html?" />
9
9
</app >
10
+ <app name =" text/csv" >
11
+ <action default =" true" ext =" " name =" view" urlsrc =" http://view.csv.collabora.test:9980/browser/61cf2b4/cool.html?" />
12
+ </app >
10
13
<app name =" text/plain" >
11
- <action default =" true" ext =" " name =" edit" urlsrc =" http://collabora.test:9980/browser/61cf2b4/cool.html?" />
14
+ <action default =" true" ext =" " name =" view" urlsrc =" http://collabora.test:9980/browser/61cf2b4/cool.html?" />
15
+ </app >
16
+ <app name =" image/png" >
17
+ <action urlsrc =" http://png.collabora.test:9980/browser/61cf2b4/cool.html?" />
12
18
</app >
13
19
</net-zone >
14
20
</wopi-discovery >
Original file line number Diff line number Diff line change @@ -34,6 +34,24 @@ public function testWopiClientUrl(): void {
34
34
$ this ->assertNull (
35
35
$ discovery ->getWopiClientURL ('text/unknown ' ),
36
36
);
37
+ $ this ->assertSame (
38
+ 'http://csv.collabora.test:9980/browser/61cf2b4/cool.html? ' ,
39
+ $ discovery ->getWopiClientURL ('text/csv ' , TRUE ),
40
+ );
41
+ $ this ->assertSame (
42
+ 'http://view.csv.collabora.test:9980/browser/61cf2b4/cool.html? ' ,
43
+ $ discovery ->getWopiClientURL ('text/csv ' , FALSE ),
44
+ );
45
+ // Test the default MIME type 'text/plain' which has only 'edit' action in
46
+ // the example file, but no 'view' action.
47
+ $ this ->assertNull ($ discovery ->getWopiClientURL (edit: TRUE ));
48
+ $ this ->assertNotNull ($ discovery ->getWopiClientURL (edit: FALSE ));
49
+ // Test a MIME type with no action name specified.
50
+ // This does not occur in the known discovery.xml, but we still want a
51
+ // well-defined behavior in that case.
52
+ $ this ->assertNull ($ discovery ->getWopiClientURL ('image/png ' , TRUE ));
53
+ $ this ->assertNull ($ discovery ->getWopiClientURL ('image/png ' , FALSE ));
54
+ $ this ->assertNotNull ($ discovery ->getWopiClientURL ('image/png ' ));
37
55
}
38
56
39
57
/**
You can’t perform that action at this time.
0 commit comments