/
exportcontroller.php
executable file
·145 lines (115 loc) · 3.86 KB
/
exportcontroller.php
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* ownCloud - CalendarPlus
*
* @author Sebastian Doell
* @copyright 2015 sebastian doell sebastian@libasys.de
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\CalendarPlus\Controller;
use \OCA\CalendarPlus\App as CalendarApp;
use \OCA\CalendarPlus\Calendar as CalendarCalendar;
use \OCA\CalendarPlus\VObject;
use \OCA\CalendarPlus\Object;
use \OCA\CalendarPlus\Export;
use \OCP\AppFramework\Controller;
use \OCP\AppFramework\Http\JSONResponse;
use \OCP\AppFramework\Http\DataDownloadResponse;
use \OCP\IRequest;
use \OCP\Share;
use \OCP\IConfig;
class ExportController extends Controller {
private $userId;
private $l10n;
private $configInfo;
public function __construct($appName, IRequest $request, $userId, $l10n, IConfig $settings) {
parent::__construct($appName, $request);
$this -> userId = $userId;
$this->l10n = $l10n;
$this->configInfo = $settings;
}
/**
*@PublicPage
* @NoCSRFRequired
*
*/
public function exportEvents(){
$token = $this -> params('t');
$calid = null;
$eventid = null;
if (isset($token)) {
$linkItem = \OCP\Share::getShareByToken($token, false);
if (is_array($linkItem) && isset($linkItem['uid_owner']) && !isset($linkItem['share_with'])) {
$rootLinkItem = \OCP\Share::resolveReShare($linkItem);
if (isset($rootLinkItem['uid_owner'])) {
\OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
if($linkItem['item_type'] === CalendarApp::SHARECALENDAR){
$sPrefix =CalendarApp::SHARECALENDARPREFIX;
}
if($linkItem['item_type'] === CalendarApp::SHAREEVENT){
$sPrefix = CalendarApp::SHAREEVENTPREFIX;
}
if($linkItem['item_type'] === CalendarApp::SHARETODO){
$sPrefix = CalendarApp::SHARETODOPREFIX;
}
$itemSource =CalendarApp::validateItemSource($linkItem['item_source'],$sPrefix);
if($linkItem['item_type'] === CalendarApp::SHARECALENDAR){
$calid=$itemSource;
}
if($linkItem['item_type'] === CalendarApp::SHAREEVENT || $linkItem['item_type'] === CalendarApp::SHARETODO){
$eventid=$itemSource;
}
}
}
}
else{
if (\OCP\User::isLoggedIn()) {
$calid = $this -> params('calid');
$eventid = $this -> params('eventid');
}
}
if(!is_null($calid)) {
//check shared calendar also
$calendar = CalendarApp::getCalendar($calid, true, true);
if(!$calendar) {
$params = [
'status' => 'error',
];
$response = new JSONResponse($params);
return $response;
}
$name = str_replace(' ', '_', $calendar['displayname']) . '.ics';
$calendarEvents = Export::export($calid, Export::CALENDAR);
$response = new DataDownloadResponse($calendarEvents, $name, 'text/calendar');
$response->addHeader('last-modified',$calendar['lastmodifieddate']);
return $response;
}
if(!is_null($eventid)) {
$data = CalendarApp::getEventObject($eventid, false);
if(!$data) {
$params = [
'status' => 'error',
];
$response = new JSONResponse($params);
return $response;
}
$name = str_replace(' ', '_', $data['summary']) . '.ics';
$singleEvent = Export::export($eventid, Export::EVENT);
$response = new DataDownloadResponse($singleEvent, $name, 'text/calendar');
return $response;
}
}
}