ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarRemoteAccessHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Refinery\Factory as Refinery;
22use ILIAS\HTTP\Services as HTTPServices;
23
30{
31 protected const LIMITED_QUERY_PARAM = 'limited';
32
34 protected ?Refinery $refinery = null;
35 protected ?HTTPServices $http = null;
36 protected ?ilLogger $logger = null;
37 protected ?ilLanguage $lng = null;
38 protected bool $limit_enabled;
39
40 public function __construct()
41 {
42 }
43
45 {
47 }
48
52 public function parseRequest(): void
53 {
54 // before initialization: $_GET and $_COOKIE is required is unavoidable
55 // in the moment.
56 if ($_GET['client_id']) {
57 $_COOKIE['ilClientId'] = $_GET['client_id'];
58 } else {
59 $path_info_components = explode('/', $_SERVER['PATH_INFO']);
60 $_COOKIE['ilClientId'] = $path_info_components[1];
61 }
62 }
63
64 public function handleRequest(): bool
65 {
66 session_name('ILCALSESSID');
67 $this->initIlias();
68 $logger = $GLOBALS['DIC']->logger()->cal();
69 $this->initTokenHandler();
70 $this->initLimitEnabled();
71
72 if (!$this->initUser()) {
73 $logger->warning('Calendar token is invalid. Authentication failed.');
74 return false;
75 }
76
77 if ($this->getTokenHandler()->getIcal() and !$this->getTokenHandler()->isIcalExpired()) {
78 $GLOBALS['DIC']['ilAuthSession']->logout();
79 ilUtil::deliverData($this->getTokenHandler()->getIcal(), 'calendar.ics', 'text/calendar');
80 exit;
81 }
82
83 if ($this->getTokenHandler()->getSelectionType() == ilCalendarAuthenticationToken::SELECTION_CALENDAR) {
84 #$export = new ilCalendarExport(array($this->getTokenHandler()->getCalendar()));
86 $cats->initialize(ilCalendarCategories::MODE_REMOTE_SELECTED, $this->getTokenHandler()->getCalendar());
87 $export = new ilCalendarExport($cats->getCategories(true), $this->limit_enabled);
88 } else {
91 $export = new ilCalendarExport($cats->getCategories(true), $this->limit_enabled);
92 }
93
94 $export->export();
95
96 $this->getTokenHandler()->setIcal($export->getExportString());
97 $this->getTokenHandler()->storeIcal();
98
99 $GLOBALS['DIC']['ilAuthSession']->logout();
100 ilUtil::deliverData($export->getExportString(), 'calendar.ics', 'text/calendar');
101 exit;
102 }
103
104 protected function initTokenHandler(): void
105 {
106 global $DIC;
107
108 $this->http = $DIC->http();
109 $this->refinery = $DIC->refinery();
110
111 $token = '';
112 if ($this->http->wrapper()->query()->has('token')) {
113 $token = $this->http->wrapper()->query()->retrieve(
114 'token',
115 $this->refinery->kindlyTo()->string()
116 );
117 }
118 $this->logger->info('Authentication token: ' . $token);
119 $this->token_handler = new ilCalendarAuthenticationToken(
121 $token
122 );
123 }
124
125 protected function initLimitEnabled(): void
126 {
127 $this->limit_enabled = (bool) ($_GET[self::LIMITED_QUERY_PARAM] ?? false);
128 }
129
130 protected function initIlias(): void
131 {
135
136 global $DIC;
137
138 $this->lng = $DIC->language();
139 $this->lng->loadLanguageModule('dateplaner');
140 $this->logger = $DIC->logger()->cal();
141 }
142
143 protected function initUser(): bool
144 {
145 global $DIC;
146
147 if (!$this->getTokenHandler() instanceof ilCalendarAuthenticationToken) {
148 $this->logger->info('Initialisation of authentication token failed');
149 return false;
150 }
151 if (!$this->getTokenHandler()->getUserId()) {
152 $this->logger->info('No user id found for calendar synchronisation');
153 return false;
154 }
155 if (!ilObjUser::_exists($this->getTokenHandler()->getUserId())) {
156 $this->logger->notice('No valid user id found for calendar synchronisation');
157 return false;
158 }
159
160 $GLOBALS['DIC']['ilAuthSession']->setAuthenticated(true, $this->getTokenHandler()->getUserId());
162
163 if (!$DIC->user() instanceof ilObjUser) {
164 $this->logger->debug('No user object defined');
165 } else {
166 $this->logger->debug('Current user is: ' . $DIC->user()->getId());
167 }
168 return true;
169 }
170}
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
const int CONTEXT_CALENDAR_TOKEN
Calendar authentication with auth token.
static setContext(int $a_context)
Handles calendar authentication tokens for external calendar subscriptions.
static _getInstance($a_usr_id=0)
get singleton instance
@classDescription Export calendar(s) to ical format
@classDescription Handles requests from external calendar applications
parseRequest()
Fetch client id, the chosen calendar...
const CONTEXT_ICAL
static init(string $a_type)
Init context by type.
static initILIAS()
ilias initialisation
static initUserAccount()
Init user with current account id.
language handling
Component logger with individual log levels by component id.
warning(string $message, array $context=[])
User class.
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
exit
$_GET['cmd']
Definition: lti.php:26
static http()
Fetches the global http state from ILIAS.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54
$path_info_components
Definition: webdav.php:23
$token
Definition: xapitoken.php:70
$_COOKIE[session_name()]
Definition: xapitoken.php:54