ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
LegacyGotoHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\StaticURL\Handler;
22 
27 
33 class LegacyGotoHandler implements Handler
34 {
35  public function __construct()
36  {
37  }
38 
39  public const NAMESPACE = 'goto';
40  public const TARGET = 'target';
41 
42  public function getNamespace(): string
43  {
44  return self::NAMESPACE;
45  }
46 
47  public function canHandle(Request $request): bool
48  {
49  return true;
50  }
51 
56  public function handle(Request $request, Context $context, Factory $response_factory): Response
57  {
58  global $DIC, $ilPluginAdmin;
59 
60  $orig_target = $requested_target = $request->getAdditionalParameters()[self::TARGET] ?? '';
61  $context->ctrl()->setTargetScript('ilias.php');
62 
63  // THIS PARTS HAS BEEN MOVED FROM THE OLD goto.php
64  // DO NOT CHANGE ANYTHING HERE, IF YOU NEED TO CHANGE SOMETHING, IMPLEMENT A NEW HANDLER!
65 
66  // user interface plugin slot hook
67  if (is_object($ilPluginAdmin)) {
68  // search
69  foreach ($DIC["component.factory"]->getActivePluginsInSlot("uihk") as $ui_plugin) {
70  $gui_class = $ui_plugin->getUIClassInstance();
71  $gui_class->gotoHook();
72  }
73  }
74 
75  $r_pos = strpos((string) $requested_target, "_");
76  $rest = substr((string) $requested_target, $r_pos + 1);
77  $target_arr = explode("_", (string) $requested_target);
78  $target_type = $target_arr[0];
79  $target_id = $target_arr[1] ?? ''; // optional for plugins
80  $additional = $target_arr[2] ?? ''; // optional for pages
81 
82  // imprint has no ref id...
83  if ($target_type === "impr") {
84  $DIC->ctrl()->redirectToURL('ilias.php?baseClass=ilImprintGUI');
85  }
86 
87  // goto is not granted?
88  $user_id = $context->getUserId();
89  if (php_sapi_name() !== 'cli' && !\ilStartUpGUI::_checkGoto(
90  $requested_target
91  )) { // we cannot perform this in UnitTest e.g.
92  // if anonymous: go to login page
93  if ($user_id === 0 || $user_id === \ANONYMOUS_USER_ID) {
94  $url = "login.php?target="
95  . $orig_target . "&cmd=force_login&lang="
96  . $DIC->user()->getCurrentLanguage();
97  if ($DIC->http()->wrapper()->query()->has('soap_pw')) {
99  $url,
100  'soap_pw=' . $DIC->http()->wrapper()->query()->retrieve(
101  'soap_pw',
102  $DIC->refinery()->kindlyTo()->string()
103  )
104  );
105  }
106  if ($DIC->http()->wrapper()->query()->has('ext_uid')) {
108  $url,
109  'ext_uid=' . $DIC->http()->wrapper()->query()->retrieve(
110  'ext_uid',
111  $DIC->refinery()->kindlyTo()->string()
112  )
113  );
114  }
115  $DIC->ctrl()->redirectToURL($url);
116  } else {
117  // message if target given but not accessible
118  $tarr = explode("_", (string) $requested_target);
119  if ($tarr[0] !== "pg" && $tarr[0] !== "st" && isset($tarr[1]) && is_numeric($tarr[1]) && $tarr[1] > 0) {
120  $DIC->ui()->mainTemplate()->setOnScreenMessage(
121  'failure',
122  sprintf(
123  $DIC->language()->txt("msg_no_perm_read_item"),
125  ),
126  true
127  );
128  } else {
129  global $DIC;
130  $DIC->ui()->mainTemplate()->setOnScreenMessage(
131  'failure',
132  $DIC->language()->txt('permission_denied'),
133  true
134  );
135  }
136  $DIC->ctrl()->redirectToURL(\ilUserUtil::getStartingPointAsUrl());
137  }
138  }
139 
140  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
141  //
142  // FOR NEW OBJECT TYPES:
143  // PLEASE USE DEFAULT IMPLEMENTATION ONLY
144  //
145  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
146 
147  switch ($target_type) {
148  // exception, must be kept for now
149  case "pg":
151  break;
152 
153  // exception, must be kept for now
154  case "st":
155  \ilStructureObjectGUI::_goto($target_id, (int) $additional);
156  break;
157 
158  // exception, must be kept for now
159  case "git":
160  $target_ref_id = $target_arr[2] ?? 0;
161  \ilGlossaryTermGUI::_goto($target_id, (int) $target_ref_id);
162  break;
163 
164  // please migrate to default branch implementation
165  case "glo":
166  \ilObjGlossaryGUI::_goto($target_id);
167  break;
168 
169  // please migrate to default branch implementation
170  case "lm":
171  \ilObjContentObjectGUI::_goto($target_id);
172  break;
173 
174  // please migrate to default branch implementation
175  case "htlm":
176  \ilObjFileBasedLMGUI::_goto($target_id);
177  break;
178 
179  // please migrate to default branch implementation
180  case "frm":
181  $target_thread = $target_arr[2] ?? 0;
182  $target_posting = $target_arr[3] ?? 0;
183  \ilObjForumGUI::_goto($target_id, $target_thread, $target_posting);
184  break;
185 
186  // please migrate to default branch implementation
187  case "exc":
188  \ilObjExerciseGUI::_goto($target_id, $rest);
189  break;
190 
191  // please migrate to default branch implementation
192  case "tst":
193  \ilObjTestGUI::_goto($target_id);
194  break;
195 
196  // please migrate to default branch implementation
197  case "qpl":
198  \ilObjQuestionPoolGUI::_goto($target_id);
199  break;
200 
201  // please migrate to default branch implementation
202  case "webr":
203  \ilObjLinkResourceGUI::_goto($target_id, $rest);
204  break;
205 
206  // please migrate to default branch implementation
207  case "sahs":
209  break;
210 
211  // please migrate to default branch implementation
212  case "crs":
213  \ilObjCourseGUI::_goto($target_id, $additional);
214  break;
215 
216  // please migrate to default branch implementation
217  case "grp":
218  \ilObjGroupGUI::_goto($target_id, $additional);
219  break;
220 
221  // please migrate to default branch implementation
222  case 'cert':
223  \ilCertificate::_goto($target_id);
224  break;
225 
226  //
227  // default implementation (should be used by all new object types)
228  //
229  default:
230  global $objDefinition;
231  if (!$objDefinition->isPlugin($target_type)) {
232  $class_name = "ilObj" . $objDefinition->getClassName($target_type) . "GUI";
233  if (class_exists($class_name)) {
234  call_user_func([$class_name, "_goto"], $rest);
235  }
236  } else {
237  $class_name = "ilObj" . $objDefinition->getClassName($target_type) . "GUI";
238  $location = $objDefinition->getLocation($target_type);
239  if (is_file($location . "/class." . $class_name . ".php")) {
240  call_user_func([$class_name, "_goto"], [$rest, $class_name]);
241  }
242  }
243  break;
244  }
245 
246  return $response_factory->cannot();
247  }
248 }
static _goto($target)
Redirect script to call a test with the test reference id.
static _goto(string $a_target, $a_additional=null)
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
$context
Definition: webdav.php:31
const ANONYMOUS_USER_ID
Definition: constants.php:27
static _goto(string $a_target)
goto target course
static _goto(string $a_target)
static _goto($a_target, string $a_add="")
static _goto($a_target, $a_thread=0, $a_posting=0)
$location
Definition: buildRTE.php:22
static _goto(string $a_target, string $a_add="")
static _goto(string $a_target, int $a_target_ref_id=0)
$url
Definition: shib_logout.php:66
static _lookupObjId(int $ref_id)
static _goto(string $a_target)
static _lookupTitle(int $obj_id)
static _goto(string $a_target, int $a_ref_id=0)
static _goto(string $a_target)
redirect script
static _goto(string $a_target)
global $DIC
Definition: shib_login.php:22
handle(Request $request, Context $context, Factory $response_factory)