[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This file contains a controller for receiving LTI service requests 19 * 20 * @package mod_lti 21 * @copyright 2014 Vital Source Technologies http://vitalsource.com 22 * @author Stephen Vickers 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 define('NO_DEBUG_DISPLAY', true); 27 define('NO_MOODLE_COOKIES', true); 28 29 require_once(__DIR__ . '/../../config.php'); 30 require_once($CFG->dirroot . '/mod/lti/locallib.php'); 31 32 33 $response = new \mod_lti\local\ltiservice\response(); 34 35 $isget = $response->get_request_method() == 'GET'; 36 37 if ($isget) { 38 $response->set_accept(isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : ''); 39 } else { 40 $response->set_content_type(isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : ''); 41 } 42 43 $ok = false; 44 $path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : ''; 45 46 $accept = $response->get_accept(); 47 48 $services = lti_get_services(); 49 foreach ($services as $service) { 50 $resources = $service->get_resources(); 51 foreach ($resources as $resource) { 52 if (($isget && !empty($accept) && (strpos($accept, '*/*') === false) && 53 !in_array($accept, $resource->get_formats())) || 54 (!$isget && !in_array($response->get_content_type(), $resource->get_formats()))) { 55 continue; 56 } 57 $template = $resource->get_template(); 58 $template = preg_replace('/\{[a-zA-Z_]+\}/', '[^/]+', $template); 59 $template = preg_replace('/\{\?[0-9a-zA-Z_\-,]+\}$/', '', $template); 60 $template = str_replace('/', '\/', $template); 61 if (preg_match("/{$template}/", $path) === 1) { 62 $ok = true; 63 break 2; 64 } 65 } 66 } 67 if (!$ok) { 68 $response->set_code(400); 69 } else { 70 $body = file_get_contents('php://input'); 71 $response->set_request_data($body); 72 if (in_array($response->get_request_method(), $resource->get_methods())) { 73 $resource->execute($response); 74 } else { 75 $response->set_code(405); 76 } 77 } 78 $response->send();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |