/** * allowContentItem - Returns true if we can return LTI Link Items */ public static function allowContentItem($postdata) { if (!isset($postdata['content_item_return_url'])) { return false; } if (isset($postdata['accept_media_types'])) { $web_mimetype = 'text/html'; $m = new Mimeparse(); $web_allowed = $m->best_match(array($web_mimetype), $postdata['accept_media_types']); if ($web_mimetype != $web_allowed) { return false; } return true; } return false; }
$ltilink_allowed = $m->best_match(array($ltilink_mimetype), $_POST['accept_media_types']); } if ($ltilink_allowed && $_POST['content_item_return_url']) { print '<p><form action="json/content_json.php" method="post">' . "\n"; foreach ($_POST as $k => $v) { print '<input type="hidden" name="' . $k . '" '; print 'value="' . htmlentities($v) . '"/>'; } print '<input type="submit" value="Test LtiLink Content Item"/>'; print "</form></p>\n"; $found = true; } $fileitem_allowed = false; if (isset($_POST['accept_media_types'])) { $fileitem_mimetype = 'application/vnd.ims.imsccv1p3'; $m = new Mimeparse(); $fileitem_allowed = $m->best_match(array($fileitem_mimetype), $_POST['accept_media_types']); } if ($fileitem_allowed && $_POST['content_item_return_url']) { print '<p><form action="json/fileitem_json.php" method="post">' . "\n"; foreach ($_POST as $k => $v) { print '<input type="hidden" name="' . $k . '" '; print 'value="' . htmlentities($v) . '"/>'; } print '<input type="submit" value="Test FileItem Content Item"/>'; print "</form></p>\n"; $found = true; } if (!$found) { echo "<p>No Services are available for this launch.</p>\n"; }
<?php /** * Note from Chuck: This was downloaded from * * https://code.google.com/p/mimeparse/ * * on July 13, 2015 - it has an MIT license. * * I split it into two files to pull out the unit tests */ // Unit tests ////////////////////////////////////////////////////////////////////////////////////////////////////////// $m = new Mimeparse(); if ($m->parse_media_range("application/xml;q=1") === array(0 => "application", 1 => "xml", 2 => array("q" => "1"))) { echo "application/xml;q=1 - OK<br>"; } else { echo "application/xml;q=1 - FAIL<br>"; } if ($m->parse_media_range("application/xml") === array(0 => "application", 1 => "xml", 2 => array("q" => "1"))) { echo "application/xml - OK<br>"; } else { echo "application/xml - FAIL<br>"; } if ($m->parse_media_range("application/xml;q=") === array(0 => "application", 1 => "xml", 2 => array("q" => "1"))) { echo "application/xml;q= - OK<br>"; } else { echo "application/xml;q= - FAIL<br>"; } if ($m->parse_media_range("application/xml ; q=1;b=other") === array(0 => "application", 1 => "xml", 2 => array("q" => "1", "b" => "other"))) { echo "application/xml ; q=1;b=other - OK<br>"; } else {
/** * Matches an array of mime types against the Accept header in a request. * * @param Zend_Controller_Request_Abstract $request the request * @param array $supportedMimetypes The mime types to match against * * @return string */ public static function matchMimetypeFromRequest(Zend_Controller_Request_Abstract $request, array $supportedMimetypes) { // get accept header $acceptHeader = strtolower($request->getHeader('Accept')); require_once 'Mimeparse.php'; try { $match = @Mimeparse::best_match($supportedMimetypes, $acceptHeader); } catch (Exception $e) { $match = ''; } return $match; }