| @@ 603-623 (lines=21) @@ | ||
| 600 | * @return array associative array of preference (numeric weight >0 <=1.0 ) |
|
| 601 | * keyed by media types, and sorted by preference |
|
| 602 | */ |
|
| 603 | public function getAcceptMediaTypes() |
|
| 604 | { |
|
| 605 | $types = array(); |
|
| 606 | $accept = $this->getHeader('ACCEPT'); |
|
| 607 | ||
| 608 | if (!empty($accept)) { |
|
| 609 | $entries = explode(',', $accept); |
|
| 610 | foreach ($entries as $e) { |
|
| 611 | $mt = explode(';q=', $e); |
|
| 612 | if (!isset($mt[1])) { |
|
| 613 | $mt[1] = 1.0; |
|
| 614 | } |
|
| 615 | $types[trim($mt[0])] = (float) $mt[1]; |
|
| 616 | } |
|
| 617 | ||
| 618 | // sort list based on value |
|
| 619 | arsort($types, SORT_NUMERIC); |
|
| 620 | } |
|
| 621 | ||
| 622 | return($types); |
|
| 623 | } |
|
| 624 | ||
| 625 | /** |
|
| 626 | * getAcceptedLanguages returns the http-accept-language header as an |
|
| @@ 632-652 (lines=21) @@ | ||
| 629 | * @return array associative array of preference (numeric weight >0 <=1.0 ) |
|
| 630 | * keyed by language code, and sorted by preference |
|
| 631 | */ |
|
| 632 | public function getAcceptedLanguages() |
|
| 633 | { |
|
| 634 | $languages = array(); |
|
| 635 | $accept = $this->getHeader('ACCEPT_LANGUAGE'); |
|
| 636 | ||
| 637 | if (!empty($accept)) { |
|
| 638 | $entries = explode(',', $accept); |
|
| 639 | foreach ($entries as $e) { |
|
| 640 | $l = explode(';q=', $e); |
|
| 641 | if (!isset($l[1])) { |
|
| 642 | $l[1] = 1.0; |
|
| 643 | } |
|
| 644 | $languages[trim($l[0])] = (float) $l[1]; |
|
| 645 | } |
|
| 646 | ||
| 647 | // sort list based on value |
|
| 648 | arsort($languages, SORT_NUMERIC); |
|
| 649 | } |
|
| 650 | ||
| 651 | return($languages); |
|
| 652 | } |
|
| 653 | } |
|
| 654 | ||