ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
class.ilFileStaticURLHandler.php
Go to the documentation of this file.
1<?php
2
28
33{
34 public const DOWNLOAD = 'download';
35 public const VERSIONS = 'versions';
36 public const EDIT = 'edit';
37 public const VIEW = 'view';
39
40 public function __construct()
41 {
42 global $DIC;
44 $this->capabilities = new CapabilityBuilder(
46 $DIC->access(),
47 $DIC->ctrl(),
48 new ActionDBRepository($DIC->database()),
49 $DIC->http(),
50 $DIC['static_url.uri_builder']
51 );
52 }
53
54 public function getNamespace(): string
55 {
56 return 'file';
57 }
58
59 public function handle(Request $request, Context $context, Factory $response_factory): Response
60 {
61 $reference_id = $request->getReferenceId();
62 if ($reference_id === null) {
63 return $response_factory->cannot();
64 }
65
66 // special case for shared workspace
67 $additional_params = $request->getAdditionalParameters()[0] ?? null;
68 if ($additional_params === '_wsp') {
69 ilObjectGUI::_gotoSharedWorkspaceNode($reference_id->toInt());
70 return $response_factory->loginFirst();
71 }
72
73 $capability_context = new \ILIAS\File\Capabilities\Context(
74 $reference_id->toObjectId()->toInt(),
75 $reference_id->toInt(),
76 \ILIAS\File\Capabilities\Context::CONTEXT_REPO
77 );
78
79 $capabilities = $this->capabilities->get($capability_context);
80
81 // special case for cloned objects
82 $forced = null;
83 $referrer = $context->http()->request()->getServerParams()['HTTP_REFERER'] ?? '';
84 if (str_contains(strtolower($referrer), strtolower(ilObjectCopyGUI::class))) {
85 $forced = $capabilities->get(Capabilities::INFO_PAGE);
86 }
87
88 // Determine Capability to redirect
89 $capability = match ($additional_params) {
90 self::DOWNLOAD => $capabilities->get(Capabilities::DOWNLOAD),
91 self::VERSIONS => $capabilities->get(Capabilities::MANAGE_VERSIONS),
92 self::EDIT => $capabilities->get(Capabilities::EDIT_EXTERNAL),
93 self::VIEW => $capabilities->get(Capabilities::VIEW_EXTERNAL),
94 default => $forced ?? $capabilities->getBest(),
95 };
96
97 if (!$capability->isUnlocked() || $capability->getUri() === null) {
98 return $response_factory->loginFirst();
99 }
100
101 $uri = $capability->getUri();
102
103 return $response_factory->can($uri->getPath() . '?' . $uri->getQuery());
104 }
105
106}
loginFirst()
Convenience: the Handler cannot serve the target with the current permissions.
Definition: Factory.php:74
can(string $uri_path, bool $shift=false)
The Handler successfully resolved the target.
Definition: Factory.php:88
cannot()
The Handler cannot process the given Request at all, e.g.
Definition: Factory.php:47
readonly CapabilityBuilder $capabilities
handle(Request $request, Context $context, Factory $response_factory)
static _gotoSharedWorkspaceNode(int $wsp_id)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26