item_return.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /* For license terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Course;
  4. use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
  5. require_once __DIR__.'/../../main/inc/global.inc.php';
  6. api_protect_course_script(false);
  7. api_block_anonymous_users(false);
  8. if (empty($_POST['content_items']) || empty($_POST['data'])) {
  9. api_not_allowed(false);
  10. }
  11. $toolId = str_replace('tool:', '', $_POST['data']);
  12. $plugin = ImsLtiPlugin::create();
  13. $em = Database::getManager();
  14. /** @var Course $course */
  15. $course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
  16. /** @var ImsLtiTool|null $ltiTool */
  17. $ltiTool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', $toolId);
  18. if (!$ltiTool) {
  19. api_not_allowed();
  20. }
  21. $consumer = new OAuthConsumer(
  22. $_POST['oauth_consumer_key'],
  23. $ltiTool->getSharedSecret()
  24. );
  25. $hmacMethod = new OAuthSignatureMethod_HMAC_SHA1();
  26. $request = OAuthRequest::from_request('POST', api_get_path(WEB_PLUGIN_PATH).'ims_lti/item_return.php');
  27. $request->sign_request($hmacMethod, $consumer, '');
  28. $signature = $request->get_parameter('oauth_signature');
  29. if ($signature !== $_POST['oauth_signature']) {
  30. api_not_allowed();
  31. }
  32. $contentItems = json_decode($_POST['content_items'], true);
  33. $contentItems = $contentItems['@graph'];
  34. foreach ($contentItems as $contentItem) {
  35. if ('LtiLinkItem' === $contentItem['@type']) {
  36. if ('application/vnd.ims.lti.v1.ltilink' === $contentItem['mediaType']) {
  37. $plugin->saveItemAsLtiLink($contentItem, $ltiTool, $course);
  38. Display::addFlash(
  39. Display::return_message($plugin->get_lang('ToolAdded'), 'success')
  40. );
  41. }
  42. }
  43. }
  44. $currentUrl = api_get_path(WEB_PLUGIN_PATH).'ims_lti/start.php?id='.$ltiTool->getId();
  45. ?>
  46. <!DOCTYPE html>
  47. <html>
  48. <head>
  49. <meta charset="UTF-8">
  50. <meta name="viewport"
  51. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  52. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  53. <title>Document</title>
  54. </head>
  55. <body>
  56. <script>
  57. window.parent.location.href = '<?php echo $currentUrl ?>';
  58. </script>
  59. </body>
  60. </html>