item_return.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. $oauth = new OAuthSimple(
  22. $_POST['oauth_consumer_key'],
  23. $ltiTool->getSharedSecret()
  24. );
  25. $oauth->setAction('POST');
  26. $oauth->setSignatureMethod($_POST['oauth_signature_method']);
  27. $result = $oauth->sign(
  28. [
  29. 'path' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/item_return.php',
  30. 'parameters' => [
  31. 'content_items' => $_POST['content_items'],
  32. 'data' => $_POST['data'],
  33. 'lti_version' => $_POST['lti_version'],
  34. 'lti_message_type' => $_POST['lti_message_type'],
  35. 'oauth_nonce' => $_POST['oauth_nonce'],
  36. 'oauth_timestamp' => $_POST['oauth_timestamp'],
  37. 'oauth_signature_method' => $_POST['oauth_signature_method'],
  38. 'oauth_callback' => $_POST['oauth_callback'],
  39. ],
  40. ]
  41. );
  42. if ($result['parameters']['oauth_signature'] !== $_POST['oauth_signature']) {
  43. api_not_allowed();
  44. }
  45. $contentItems = json_decode($_POST['content_items'], true);
  46. $contentItems = $contentItems['@graph'];
  47. foreach ($contentItems as $contentItem) {
  48. if ('LtiLinkItem' === $contentItem['@type']) {
  49. if ('application/vnd.ims.lti.v1.ltilink' === $contentItem['mediaType']) {
  50. $plugin->saveItemAsLtiLink($contentItem, $ltiTool, $course);
  51. Display::addFlash(
  52. Display::return_message($plugin->get_lang('ToolAdded'), 'success')
  53. );
  54. }
  55. }
  56. }
  57. $currentUrl = api_get_path(WEB_PLUGIN_PATH).'ims_lti/start.php?id='.$ltiTool->getId();
  58. ?>
  59. <!DOCTYPE html>
  60. <html>
  61. <head>
  62. <meta charset="UTF-8">
  63. <meta name="viewport"
  64. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  65. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  66. <title>Document</title>
  67. </head>
  68. <body>
  69. <script>
  70. window.parent.location.href = '<?php echo $currentUrl ?>';
  71. </script>
  72. </body>
  73. </html>