ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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
68 require_once(__DIR__ . "/../../../../artifacts/bootstrap_default.php");
69 entry_point('ILIAS Legacy Initialisation Adapter');
70 $this->initIlias();
71
72 $logger = $GLOBALS['DIC']->logger()->cal();
73 $this->initTokenHandler();
74 $this->initLimitEnabled();
75
76 if (!$this->initUser()) {
77 $logger->warning('Calendar token is invalid. Authentication failed.');
78 return false;
79 }
80
81 if ($this->getTokenHandler()->getIcal() and !$this->getTokenHandler()->isIcalExpired()) {
82 $GLOBALS['DIC']['ilAuthSession']->logout();
83 ilUtil::deliverData($this->getTokenHandler()->getIcal(), 'calendar.ics', 'text/calendar');
84 exit;
85 }
86
87 if ($this->getTokenHandler()->getSelectionType() == ilCalendarAuthenticationToken::SELECTION_CALENDAR) {
88 #$export = new ilCalendarExport(array($this->getTokenHandler()->getCalendar()));
90 $cats->initialize(ilCalendarCategories::MODE_REMOTE_SELECTED, $this->getTokenHandler()->getCalendar());
91 $export = new ilCalendarExport($cats->getCategories(true), $this->limit_enabled);
92 } else {
95 $export = new ilCalendarExport($cats->getCategories(true), $this->limit_enabled);
96 }
97
98 $export->export();
99
100 $this->getTokenHandler()->setIcal($export->getExportString());
101 $this->getTokenHandler()->storeIcal();
102
103 $GLOBALS['DIC']['ilAuthSession']->logout();
104 ilUtil::deliverData($export->getExportString(), 'calendar.ics', 'text/calendar');
105 exit;
106 }
107
108 protected function initTokenHandler(): void
109 {
110 global $DIC;
111
112 $this->http = $DIC->http();
113 $this->refinery = $DIC->refinery();
114
115 $token = '';
116 if ($this->http->wrapper()->query()->has('token')) {
117 $token = $this->http->wrapper()->query()->retrieve(
118 'token',
119 $this->refinery->kindlyTo()->string()
120 );
121 }
122 $this->logger->info('Authentication token: ' . $token);
123 $this->token_handler = new ilCalendarAuthenticationToken(
125 $token
126 );
127 }
128
129 protected function initLimitEnabled(): void
130 {
131 $this->limit_enabled = (bool) ($_GET[self::LIMITED_QUERY_PARAM] ?? false);
132 }
133
134 protected function initIlias(): void
135 {
139
140 global $DIC;
141
142 $this->lng = $DIC->language();
143 $this->lng->loadLanguageModule('dateplaner');
144 $this->logger = $DIC->logger()->cal();
145 }
146
147 protected function initUser(): bool
148 {
149 global $DIC;
150
151 if (!$this->getTokenHandler() instanceof ilCalendarAuthenticationToken) {
152 $this->logger->info('Initialisation of authentication token failed');
153 return false;
154 }
155 if (!$this->getTokenHandler()->getUserId()) {
156 $this->logger->info('No user id found for calendar synchronisation');
157 return false;
158 }
159 if (!ilObjUser::_exists($this->getTokenHandler()->getUserId())) {
160 $this->logger->notice('No valid user id found for calendar synchronisation');
161 return false;
162 }
163
164 $GLOBALS['DIC']['ilAuthSession']->setAuthenticated(true, $this->getTokenHandler()->getUserId());
166
167 if (!$DIC->user() instanceof ilObjUser) {
168 $this->logger->debug('No user object defined');
169 } else {
170 $this->logger->debug('Current user is: ' . $DIC->user()->getId());
171 }
172 return true;
173 }
174}
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
entry_point(string $name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: result1.php:21
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54
$path_info_components
Definition: webdav.php:23
$token
Definition: xapitoken.php:67
$_COOKIE[session_name()]
Definition: xapitoken.php:52