$mime_types) { foreach ($mime_types as $mime_type) { if (in_array($mime_type, $accept)) { // Renderer found, return it. return $renderer; } } } // No renderer found. Default to html. return 'html'; } } /** * Parse HTTP Accept header and return an ordered list of mime types for * the current request. * * @return * Ordered array of mime types. */ function drupal_parse_accept_header() { $accept = array(); $accept_parts = explode(',', $_SERVER['HTTP_ACCEPT']); foreach ($accept_parts as $order => $part) { list($type, $quality) = preg_split('/;\s*q=/', $part); $accept[$type] = array( 'order' => $order, 'quality' => isset($quality) ? $quality : 1, ); } uasort($accept, '_drupal_parse_accept_header_sort'); return array_keys($accept); } /** * Helper function for sorting Accept header based on order * and quality values. * See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 */ function _drupal_parse_accept_header_sort($a, $b) { if ($a['quality'] == $b['quality']) { // Lower first. return ($a['order'] < $b['order']) ? -1 : 1; } else { // Higher first. return ($a['quality'] > $b['quality']) ? -1 : 1; } } /** * Returns a hardcoded list of renderers along with their supported mime types. */ function drupal_get_renderers() { // A hook should allow modules to add/alter types. // Specialized xml types should take precedence over 'xml'. return array( 'html' => array('text/html', 'application/xhtml+xml'), 'xml' => array('application/xml', 'text/xml', 'application/x-xml'), 'json' => array('application/json', 'text/x-json'), 'javascript' => array('application/javascript', 'text/javascript', 'application/x-javascript'), 'text' => array('text/plain'), ); } ?>