ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ConfigurableLogoutTarget.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ilLink;
24 use ilObject;
25 use ilSetting;
26 use ILIAS\Data\URI;
27 use ilCtrlInterface;
30 use ilAccessHandler;
31 
33 {
34  public const INTERNAL_RESSOURCE = 'internal_ressource';
35  public const EXTERNAL_RESSOURCE = 'external_ressource';
36 
37  public function __construct(
38  private readonly ilCtrlInterface $ctrl,
39  private readonly ilSetting $settings,
40  private readonly ilAccessHandler $access,
41  private readonly string $http_path = ILIAS_HTTP_PATH,
42  ) {
43  }
44 
45  public function asURI(): URI
46  {
47  switch ($this->settings->get('logout_behaviour', '')) {
48  case LogoutDestinations::LOGIN_SCREEN->value:
49  return LogoutDestinations::LOGIN_SCREEN->asURI($this->ctrl, $this->http_path);
50 
51  case self::INTERNAL_RESSOURCE:
52  $ref_id = (int) $this->settings->get('logout_behaviour_ref_id', '0');
53  if ($this->isValidInternalResource($ref_id)) {
54  return new URI(ilLink::_getStaticLink($ref_id));
55  }
56 
57  break;
58 
59  case self::EXTERNAL_RESSOURCE:
60  $url = $this->settings->get('logout_behaviour_url', '');
61  if ($url && $this->isValidExternalResource($url)) {
62  return new URI($url);
63  }
64  break;
65 
66  case LogoutDestinations::LOGOUT_SCREEN->value:
67  default:
68  break;
69  }
70 
71  return LogoutDestinations::LOGOUT_SCREEN->asURI($this->ctrl, $this->http_path);
72  }
73 
74  public function isValidInternalResource(int $ref_id): bool
75  {
76  return $this->isInRepository($ref_id) && $this->isAnonymousAccessible($ref_id);
77  }
78 
79  public function isInRepository(int $ref_id): bool
80  {
81  return ilObject::_exists($ref_id, true) && !ilObject::_isInTrash($ref_id);
82  }
83 
84  public function isAnonymousAccessible(int $ref_id): bool
85  {
86  return $this->access->checkAccessOfUser(ANONYMOUS_USER_ID, 'read', '', $ref_id);
87  }
88 
89  public function isValidExternalResource(string $url): bool
90  {
91  try {
92  $uri = new URI($url);
93  } catch (InvalidArgumentException) {
94  return false;
95  }
96 
97  return filter_var($url, FILTER_VALIDATE_URL) !== false;
98  }
99 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
$url
Definition: shib_logout.php:66
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
$ref_id
Definition: ltiauth.php:65
static _isInTrash(int $ref_id)
__construct(private readonly ilCtrlInterface $ctrl, private readonly ilSetting $settings, private readonly ilAccessHandler $access, private readonly string $http_path=ILIAS_HTTP_PATH,)