4425 $title = null; |
4433 $title = null; |
4426 |
4434 |
4427 // If we have media:group tags, loop through them. |
4435 // If we have media:group tags, loop through them. |
4428 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group) |
4436 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group) |
4429 { |
4437 { |
4430 // If we have media:content tags, loop through them. |
4438 if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'])) |
4431 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content) |
4439 { |
4432 { |
4440 // If we have media:content tags, loop through them. |
4433 if (isset($content['attribs']['']['url'])) |
4441 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content) |
|
4442 { |
|
4443 if (isset($content['attribs']['']['url'])) |
|
4444 { |
|
4445 // Attributes |
|
4446 $bitrate = null; |
|
4447 $channels = null; |
|
4448 $duration = null; |
|
4449 $expression = null; |
|
4450 $framerate = null; |
|
4451 $height = null; |
|
4452 $javascript = null; |
|
4453 $lang = null; |
|
4454 $length = null; |
|
4455 $medium = null; |
|
4456 $samplingrate = null; |
|
4457 $type = null; |
|
4458 $url = null; |
|
4459 $width = null; |
|
4460 |
|
4461 // Elements |
|
4462 $captions = null; |
|
4463 $categories = null; |
|
4464 $copyrights = null; |
|
4465 $credits = null; |
|
4466 $description = null; |
|
4467 $hashes = null; |
|
4468 $keywords = null; |
|
4469 $player = null; |
|
4470 $ratings = null; |
|
4471 $restrictions = null; |
|
4472 $thumbnails = null; |
|
4473 $title = null; |
|
4474 |
|
4475 // Start checking the attributes of media:content |
|
4476 if (isset($content['attribs']['']['bitrate'])) |
|
4477 { |
|
4478 $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4479 } |
|
4480 if (isset($content['attribs']['']['channels'])) |
|
4481 { |
|
4482 $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4483 } |
|
4484 if (isset($content['attribs']['']['duration'])) |
|
4485 { |
|
4486 $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4487 } |
|
4488 else |
|
4489 { |
|
4490 $duration = $duration_parent; |
|
4491 } |
|
4492 if (isset($content['attribs']['']['expression'])) |
|
4493 { |
|
4494 $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4495 } |
|
4496 if (isset($content['attribs']['']['framerate'])) |
|
4497 { |
|
4498 $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4499 } |
|
4500 if (isset($content['attribs']['']['height'])) |
|
4501 { |
|
4502 $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4503 } |
|
4504 if (isset($content['attribs']['']['lang'])) |
|
4505 { |
|
4506 $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4507 } |
|
4508 if (isset($content['attribs']['']['fileSize'])) |
|
4509 { |
|
4510 $length = ceil($content['attribs']['']['fileSize']); |
|
4511 } |
|
4512 if (isset($content['attribs']['']['medium'])) |
|
4513 { |
|
4514 $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4515 } |
|
4516 if (isset($content['attribs']['']['samplingrate'])) |
|
4517 { |
|
4518 $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4519 } |
|
4520 if (isset($content['attribs']['']['type'])) |
|
4521 { |
|
4522 $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4523 } |
|
4524 if (isset($content['attribs']['']['width'])) |
|
4525 { |
|
4526 $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4527 } |
|
4528 $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
|
4529 |
|
4530 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel |
|
4531 |
|
4532 // CAPTIONS |
|
4533 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) |
|
4534 { |
|
4535 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption) |
|
4536 { |
|
4537 $caption_type = null; |
|
4538 $caption_lang = null; |
|
4539 $caption_startTime = null; |
|
4540 $caption_endTime = null; |
|
4541 $caption_text = null; |
|
4542 if (isset($caption['attribs']['']['type'])) |
|
4543 { |
|
4544 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4545 } |
|
4546 if (isset($caption['attribs']['']['lang'])) |
|
4547 { |
|
4548 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4549 } |
|
4550 if (isset($caption['attribs']['']['start'])) |
|
4551 { |
|
4552 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4553 } |
|
4554 if (isset($caption['attribs']['']['end'])) |
|
4555 { |
|
4556 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4557 } |
|
4558 if (isset($caption['data'])) |
|
4559 { |
|
4560 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4561 } |
|
4562 $captions[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); |
|
4563 } |
|
4564 if (is_array($captions)) |
|
4565 { |
|
4566 $captions = array_values(SimplePie_Misc::array_unique($captions)); |
|
4567 } |
|
4568 } |
|
4569 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) |
|
4570 { |
|
4571 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption) |
|
4572 { |
|
4573 $caption_type = null; |
|
4574 $caption_lang = null; |
|
4575 $caption_startTime = null; |
|
4576 $caption_endTime = null; |
|
4577 $caption_text = null; |
|
4578 if (isset($caption['attribs']['']['type'])) |
|
4579 { |
|
4580 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4581 } |
|
4582 if (isset($caption['attribs']['']['lang'])) |
|
4583 { |
|
4584 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4585 } |
|
4586 if (isset($caption['attribs']['']['start'])) |
|
4587 { |
|
4588 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4589 } |
|
4590 if (isset($caption['attribs']['']['end'])) |
|
4591 { |
|
4592 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4593 } |
|
4594 if (isset($caption['data'])) |
|
4595 { |
|
4596 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4597 } |
|
4598 $captions[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); |
|
4599 } |
|
4600 if (is_array($captions)) |
|
4601 { |
|
4602 $captions = array_values(SimplePie_Misc::array_unique($captions)); |
|
4603 } |
|
4604 } |
|
4605 else |
|
4606 { |
|
4607 $captions = $captions_parent; |
|
4608 } |
|
4609 |
|
4610 // CATEGORIES |
|
4611 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'])) |
|
4612 { |
|
4613 foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category) |
|
4614 { |
|
4615 $term = null; |
|
4616 $scheme = null; |
|
4617 $label = null; |
|
4618 if (isset($category['data'])) |
|
4619 { |
|
4620 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4621 } |
|
4622 if (isset($category['attribs']['']['scheme'])) |
|
4623 { |
|
4624 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4625 } |
|
4626 else |
|
4627 { |
|
4628 $scheme = 'http://search.yahoo.com/mrss/category_schema'; |
|
4629 } |
|
4630 if (isset($category['attribs']['']['label'])) |
|
4631 { |
|
4632 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4633 } |
|
4634 $categories[] =& new $this->feed->category_class($term, $scheme, $label); |
|
4635 } |
|
4636 } |
|
4637 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'])) |
|
4638 { |
|
4639 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category) |
|
4640 { |
|
4641 $term = null; |
|
4642 $scheme = null; |
|
4643 $label = null; |
|
4644 if (isset($category['data'])) |
|
4645 { |
|
4646 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4647 } |
|
4648 if (isset($category['attribs']['']['scheme'])) |
|
4649 { |
|
4650 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4651 } |
|
4652 else |
|
4653 { |
|
4654 $scheme = 'http://search.yahoo.com/mrss/category_schema'; |
|
4655 } |
|
4656 if (isset($category['attribs']['']['label'])) |
|
4657 { |
|
4658 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4659 } |
|
4660 $categories[] =& new $this->feed->category_class($term, $scheme, $label); |
|
4661 } |
|
4662 } |
|
4663 if (is_array($categories) && is_array($categories_parent)) |
|
4664 { |
|
4665 $categories = array_values(SimplePie_Misc::array_unique(array_merge($categories, $categories_parent))); |
|
4666 } |
|
4667 elseif (is_array($categories)) |
|
4668 { |
|
4669 $categories = array_values(SimplePie_Misc::array_unique($categories)); |
|
4670 } |
|
4671 elseif (is_array($categories_parent)) |
|
4672 { |
|
4673 $categories = array_values(SimplePie_Misc::array_unique($categories_parent)); |
|
4674 } |
|
4675 |
|
4676 // COPYRIGHTS |
|
4677 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'])) |
|
4678 { |
|
4679 $copyright_url = null; |
|
4680 $copyright_label = null; |
|
4681 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) |
|
4682 { |
|
4683 $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4684 } |
|
4685 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'])) |
|
4686 { |
|
4687 $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4688 } |
|
4689 $copyrights =& new $this->feed->copyright_class($copyright_url, $copyright_label); |
|
4690 } |
|
4691 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'])) |
|
4692 { |
|
4693 $copyright_url = null; |
|
4694 $copyright_label = null; |
|
4695 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) |
|
4696 { |
|
4697 $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4698 } |
|
4699 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'])) |
|
4700 { |
|
4701 $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4702 } |
|
4703 $copyrights =& new $this->feed->copyright_class($copyright_url, $copyright_label); |
|
4704 } |
|
4705 else |
|
4706 { |
|
4707 $copyrights = $copyrights_parent; |
|
4708 } |
|
4709 |
|
4710 // CREDITS |
|
4711 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'])) |
|
4712 { |
|
4713 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit) |
|
4714 { |
|
4715 $credit_role = null; |
|
4716 $credit_scheme = null; |
|
4717 $credit_name = null; |
|
4718 if (isset($credit['attribs']['']['role'])) |
|
4719 { |
|
4720 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4721 } |
|
4722 if (isset($credit['attribs']['']['scheme'])) |
|
4723 { |
|
4724 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4725 } |
|
4726 else |
|
4727 { |
|
4728 $credit_scheme = 'urn:ebu'; |
|
4729 } |
|
4730 if (isset($credit['data'])) |
|
4731 { |
|
4732 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4733 } |
|
4734 $credits[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); |
|
4735 } |
|
4736 if (is_array($credits)) |
|
4737 { |
|
4738 $credits = array_values(SimplePie_Misc::array_unique($credits)); |
|
4739 } |
|
4740 } |
|
4741 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'])) |
|
4742 { |
|
4743 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit) |
|
4744 { |
|
4745 $credit_role = null; |
|
4746 $credit_scheme = null; |
|
4747 $credit_name = null; |
|
4748 if (isset($credit['attribs']['']['role'])) |
|
4749 { |
|
4750 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4751 } |
|
4752 if (isset($credit['attribs']['']['scheme'])) |
|
4753 { |
|
4754 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4755 } |
|
4756 else |
|
4757 { |
|
4758 $credit_scheme = 'urn:ebu'; |
|
4759 } |
|
4760 if (isset($credit['data'])) |
|
4761 { |
|
4762 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4763 } |
|
4764 $credits[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); |
|
4765 } |
|
4766 if (is_array($credits)) |
|
4767 { |
|
4768 $credits = array_values(SimplePie_Misc::array_unique($credits)); |
|
4769 } |
|
4770 } |
|
4771 else |
|
4772 { |
|
4773 $credits = $credits_parent; |
|
4774 } |
|
4775 |
|
4776 // DESCRIPTION |
|
4777 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'])) |
|
4778 { |
|
4779 $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4780 } |
|
4781 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'])) |
|
4782 { |
|
4783 $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4784 } |
|
4785 else |
|
4786 { |
|
4787 $description = $description_parent; |
|
4788 } |
|
4789 |
|
4790 // HASHES |
|
4791 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'])) |
|
4792 { |
|
4793 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash) |
|
4794 { |
|
4795 $value = null; |
|
4796 $algo = null; |
|
4797 if (isset($hash['data'])) |
|
4798 { |
|
4799 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4800 } |
|
4801 if (isset($hash['attribs']['']['algo'])) |
|
4802 { |
|
4803 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4804 } |
|
4805 else |
|
4806 { |
|
4807 $algo = 'md5'; |
|
4808 } |
|
4809 $hashes[] = $algo.':'.$value; |
|
4810 } |
|
4811 if (is_array($hashes)) |
|
4812 { |
|
4813 $hashes = array_values(SimplePie_Misc::array_unique($hashes)); |
|
4814 } |
|
4815 } |
|
4816 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'])) |
|
4817 { |
|
4818 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash) |
|
4819 { |
|
4820 $value = null; |
|
4821 $algo = null; |
|
4822 if (isset($hash['data'])) |
|
4823 { |
|
4824 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4825 } |
|
4826 if (isset($hash['attribs']['']['algo'])) |
|
4827 { |
|
4828 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4829 } |
|
4830 else |
|
4831 { |
|
4832 $algo = 'md5'; |
|
4833 } |
|
4834 $hashes[] = $algo.':'.$value; |
|
4835 } |
|
4836 if (is_array($hashes)) |
|
4837 { |
|
4838 $hashes = array_values(SimplePie_Misc::array_unique($hashes)); |
|
4839 } |
|
4840 } |
|
4841 else |
|
4842 { |
|
4843 $hashes = $hashes_parent; |
|
4844 } |
|
4845 |
|
4846 // KEYWORDS |
|
4847 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'])) |
|
4848 { |
|
4849 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'])) |
|
4850 { |
|
4851 $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); |
|
4852 foreach ($temp as $word) |
|
4853 { |
|
4854 $keywords[] = trim($word); |
|
4855 } |
|
4856 unset($temp); |
|
4857 } |
|
4858 if (is_array($keywords)) |
|
4859 { |
|
4860 $keywords = array_values(SimplePie_Misc::array_unique($keywords)); |
|
4861 } |
|
4862 } |
|
4863 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'])) |
|
4864 { |
|
4865 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'])) |
|
4866 { |
|
4867 $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); |
|
4868 foreach ($temp as $word) |
|
4869 { |
|
4870 $keywords[] = trim($word); |
|
4871 } |
|
4872 unset($temp); |
|
4873 } |
|
4874 if (is_array($keywords)) |
|
4875 { |
|
4876 $keywords = array_values(SimplePie_Misc::array_unique($keywords)); |
|
4877 } |
|
4878 } |
|
4879 else |
|
4880 { |
|
4881 $keywords = $keywords_parent; |
|
4882 } |
|
4883 |
|
4884 // PLAYER |
|
4885 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) |
|
4886 { |
|
4887 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
|
4888 } |
|
4889 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) |
|
4890 { |
|
4891 $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
|
4892 } |
|
4893 else |
|
4894 { |
|
4895 $player = $player_parent; |
|
4896 } |
|
4897 |
|
4898 // RATINGS |
|
4899 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'])) |
|
4900 { |
|
4901 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating) |
|
4902 { |
|
4903 $rating_scheme = null; |
|
4904 $rating_value = null; |
|
4905 if (isset($rating['attribs']['']['scheme'])) |
|
4906 { |
|
4907 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4908 } |
|
4909 else |
|
4910 { |
|
4911 $rating_scheme = 'urn:simple'; |
|
4912 } |
|
4913 if (isset($rating['data'])) |
|
4914 { |
|
4915 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4916 } |
|
4917 $ratings[] =& new $this->feed->rating_class($rating_scheme, $rating_value); |
|
4918 } |
|
4919 if (is_array($ratings)) |
|
4920 { |
|
4921 $ratings = array_values(SimplePie_Misc::array_unique($ratings)); |
|
4922 } |
|
4923 } |
|
4924 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'])) |
|
4925 { |
|
4926 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating) |
|
4927 { |
|
4928 $rating_scheme = null; |
|
4929 $rating_value = null; |
|
4930 if (isset($rating['attribs']['']['scheme'])) |
|
4931 { |
|
4932 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4933 } |
|
4934 else |
|
4935 { |
|
4936 $rating_scheme = 'urn:simple'; |
|
4937 } |
|
4938 if (isset($rating['data'])) |
|
4939 { |
|
4940 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4941 } |
|
4942 $ratings[] =& new $this->feed->rating_class($rating_scheme, $rating_value); |
|
4943 } |
|
4944 if (is_array($ratings)) |
|
4945 { |
|
4946 $ratings = array_values(SimplePie_Misc::array_unique($ratings)); |
|
4947 } |
|
4948 } |
|
4949 else |
|
4950 { |
|
4951 $ratings = $ratings_parent; |
|
4952 } |
|
4953 |
|
4954 // RESTRICTIONS |
|
4955 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'])) |
|
4956 { |
|
4957 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction) |
|
4958 { |
|
4959 $restriction_relationship = null; |
|
4960 $restriction_type = null; |
|
4961 $restriction_value = null; |
|
4962 if (isset($restriction['attribs']['']['relationship'])) |
|
4963 { |
|
4964 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4965 } |
|
4966 if (isset($restriction['attribs']['']['type'])) |
|
4967 { |
|
4968 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4969 } |
|
4970 if (isset($restriction['data'])) |
|
4971 { |
|
4972 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4973 } |
|
4974 $restrictions[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); |
|
4975 } |
|
4976 if (is_array($restrictions)) |
|
4977 { |
|
4978 $restrictions = array_values(SimplePie_Misc::array_unique($restrictions)); |
|
4979 } |
|
4980 } |
|
4981 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'])) |
|
4982 { |
|
4983 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction) |
|
4984 { |
|
4985 $restriction_relationship = null; |
|
4986 $restriction_type = null; |
|
4987 $restriction_value = null; |
|
4988 if (isset($restriction['attribs']['']['relationship'])) |
|
4989 { |
|
4990 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4991 } |
|
4992 if (isset($restriction['attribs']['']['type'])) |
|
4993 { |
|
4994 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4995 } |
|
4996 if (isset($restriction['data'])) |
|
4997 { |
|
4998 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4999 } |
|
5000 $restrictions[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); |
|
5001 } |
|
5002 if (is_array($restrictions)) |
|
5003 { |
|
5004 $restrictions = array_values(SimplePie_Misc::array_unique($restrictions)); |
|
5005 } |
|
5006 } |
|
5007 else |
|
5008 { |
|
5009 $restrictions = $restrictions_parent; |
|
5010 } |
|
5011 |
|
5012 // THUMBNAILS |
|
5013 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'])) |
|
5014 { |
|
5015 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) |
|
5016 { |
|
5017 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
|
5018 } |
|
5019 if (is_array($thumbnails)) |
|
5020 { |
|
5021 $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails)); |
|
5022 } |
|
5023 } |
|
5024 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'])) |
|
5025 { |
|
5026 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) |
|
5027 { |
|
5028 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
|
5029 } |
|
5030 if (is_array($thumbnails)) |
|
5031 { |
|
5032 $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails)); |
|
5033 } |
|
5034 } |
|
5035 else |
|
5036 { |
|
5037 $thumbnails = $thumbnails_parent; |
|
5038 } |
|
5039 |
|
5040 // TITLES |
|
5041 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'])) |
|
5042 { |
|
5043 $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5044 } |
|
5045 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'])) |
|
5046 { |
|
5047 $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5048 } |
|
5049 else |
|
5050 { |
|
5051 $title = $title_parent; |
|
5052 } |
|
5053 |
|
5054 $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width); |
|
5055 } |
|
5056 } |
|
5057 } |
|
5058 } |
|
5059 |
|
5060 // If we have standalone media:content tags, loop through them. |
|
5061 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'])) |
|
5062 { |
|
5063 foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content) |
|
5064 { |
|
5065 if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) |
4434 { |
5066 { |
4435 // Attributes |
5067 // Attributes |
4436 $bitrate = null; |
5068 $bitrate = null; |
4437 $channels = null; |
5069 $channels = null; |
4438 $duration = null; |
5070 $duration = null; |
4513 } |
5145 } |
4514 if (isset($content['attribs']['']['width'])) |
5146 if (isset($content['attribs']['']['width'])) |
4515 { |
5147 { |
4516 $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT); |
5148 $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT); |
4517 } |
5149 } |
4518 $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
5150 if (isset($content['attribs']['']['url'])) |
4519 |
|
4520 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel |
|
4521 |
|
4522 // CAPTIONS |
|
4523 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) |
|
4524 { |
5151 { |
4525 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption) |
5152 $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
4526 { |
|
4527 $caption_type = null; |
|
4528 $caption_lang = null; |
|
4529 $caption_startTime = null; |
|
4530 $caption_endTime = null; |
|
4531 $caption_text = null; |
|
4532 if (isset($caption['attribs']['']['type'])) |
|
4533 { |
|
4534 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4535 } |
|
4536 if (isset($caption['attribs']['']['lang'])) |
|
4537 { |
|
4538 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4539 } |
|
4540 if (isset($caption['attribs']['']['start'])) |
|
4541 { |
|
4542 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4543 } |
|
4544 if (isset($caption['attribs']['']['end'])) |
|
4545 { |
|
4546 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4547 } |
|
4548 if (isset($caption['data'])) |
|
4549 { |
|
4550 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4551 } |
|
4552 $captions[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); |
|
4553 } |
|
4554 if (is_array($captions)) |
|
4555 { |
|
4556 $captions = array_values(SimplePie_Misc::array_unique($captions)); |
|
4557 } |
|
4558 } |
5153 } |
4559 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) |
|
4560 { |
|
4561 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption) |
|
4562 { |
|
4563 $caption_type = null; |
|
4564 $caption_lang = null; |
|
4565 $caption_startTime = null; |
|
4566 $caption_endTime = null; |
|
4567 $caption_text = null; |
|
4568 if (isset($caption['attribs']['']['type'])) |
|
4569 { |
|
4570 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4571 } |
|
4572 if (isset($caption['attribs']['']['lang'])) |
|
4573 { |
|
4574 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4575 } |
|
4576 if (isset($caption['attribs']['']['start'])) |
|
4577 { |
|
4578 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4579 } |
|
4580 if (isset($caption['attribs']['']['end'])) |
|
4581 { |
|
4582 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4583 } |
|
4584 if (isset($caption['data'])) |
|
4585 { |
|
4586 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4587 } |
|
4588 $captions[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); |
|
4589 } |
|
4590 if (is_array($captions)) |
|
4591 { |
|
4592 $captions = array_values(SimplePie_Misc::array_unique($captions)); |
|
4593 } |
|
4594 } |
|
4595 else |
|
4596 { |
|
4597 $captions = $captions_parent; |
|
4598 } |
|
4599 |
|
4600 // CATEGORIES |
|
4601 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'])) |
|
4602 { |
|
4603 foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category) |
|
4604 { |
|
4605 $term = null; |
|
4606 $scheme = null; |
|
4607 $label = null; |
|
4608 if (isset($category['data'])) |
|
4609 { |
|
4610 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4611 } |
|
4612 if (isset($category['attribs']['']['scheme'])) |
|
4613 { |
|
4614 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4615 } |
|
4616 else |
|
4617 { |
|
4618 $scheme = 'http://search.yahoo.com/mrss/category_schema'; |
|
4619 } |
|
4620 if (isset($category['attribs']['']['label'])) |
|
4621 { |
|
4622 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4623 } |
|
4624 $categories[] =& new $this->feed->category_class($term, $scheme, $label); |
|
4625 } |
|
4626 } |
|
4627 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'])) |
|
4628 { |
|
4629 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category) |
|
4630 { |
|
4631 $term = null; |
|
4632 $scheme = null; |
|
4633 $label = null; |
|
4634 if (isset($category['data'])) |
|
4635 { |
|
4636 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4637 } |
|
4638 if (isset($category['attribs']['']['scheme'])) |
|
4639 { |
|
4640 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4641 } |
|
4642 else |
|
4643 { |
|
4644 $scheme = 'http://search.yahoo.com/mrss/category_schema'; |
|
4645 } |
|
4646 if (isset($category['attribs']['']['label'])) |
|
4647 { |
|
4648 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4649 } |
|
4650 $categories[] =& new $this->feed->category_class($term, $scheme, $label); |
|
4651 } |
|
4652 } |
|
4653 if (is_array($categories) && is_array($categories_parent)) |
|
4654 { |
|
4655 $categories = array_values(SimplePie_Misc::array_unique(array_merge($categories, $categories_parent))); |
|
4656 } |
|
4657 elseif (is_array($categories)) |
|
4658 { |
|
4659 $categories = array_values(SimplePie_Misc::array_unique($categories)); |
|
4660 } |
|
4661 elseif (is_array($categories_parent)) |
|
4662 { |
|
4663 $categories = array_values(SimplePie_Misc::array_unique($categories_parent)); |
|
4664 } |
|
4665 |
|
4666 // COPYRIGHTS |
|
4667 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'])) |
|
4668 { |
|
4669 $copyright_url = null; |
|
4670 $copyright_label = null; |
|
4671 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) |
|
4672 { |
|
4673 $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4674 } |
|
4675 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'])) |
|
4676 { |
|
4677 $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4678 } |
|
4679 $copyrights =& new $this->feed->copyright_class($copyright_url, $copyright_label); |
|
4680 } |
|
4681 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'])) |
|
4682 { |
|
4683 $copyright_url = null; |
|
4684 $copyright_label = null; |
|
4685 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) |
|
4686 { |
|
4687 $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4688 } |
|
4689 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'])) |
|
4690 { |
|
4691 $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4692 } |
|
4693 $copyrights =& new $this->feed->copyright_class($copyright_url, $copyright_label); |
|
4694 } |
|
4695 else |
|
4696 { |
|
4697 $copyrights = $copyrights_parent; |
|
4698 } |
|
4699 |
|
4700 // CREDITS |
|
4701 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'])) |
|
4702 { |
|
4703 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit) |
|
4704 { |
|
4705 $credit_role = null; |
|
4706 $credit_scheme = null; |
|
4707 $credit_name = null; |
|
4708 if (isset($credit['attribs']['']['role'])) |
|
4709 { |
|
4710 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4711 } |
|
4712 if (isset($credit['attribs']['']['scheme'])) |
|
4713 { |
|
4714 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4715 } |
|
4716 else |
|
4717 { |
|
4718 $credit_scheme = 'urn:ebu'; |
|
4719 } |
|
4720 if (isset($credit['data'])) |
|
4721 { |
|
4722 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4723 } |
|
4724 $credits[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); |
|
4725 } |
|
4726 if (is_array($credits)) |
|
4727 { |
|
4728 $credits = array_values(SimplePie_Misc::array_unique($credits)); |
|
4729 } |
|
4730 } |
|
4731 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'])) |
|
4732 { |
|
4733 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit) |
|
4734 { |
|
4735 $credit_role = null; |
|
4736 $credit_scheme = null; |
|
4737 $credit_name = null; |
|
4738 if (isset($credit['attribs']['']['role'])) |
|
4739 { |
|
4740 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4741 } |
|
4742 if (isset($credit['attribs']['']['scheme'])) |
|
4743 { |
|
4744 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4745 } |
|
4746 else |
|
4747 { |
|
4748 $credit_scheme = 'urn:ebu'; |
|
4749 } |
|
4750 if (isset($credit['data'])) |
|
4751 { |
|
4752 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4753 } |
|
4754 $credits[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); |
|
4755 } |
|
4756 if (is_array($credits)) |
|
4757 { |
|
4758 $credits = array_values(SimplePie_Misc::array_unique($credits)); |
|
4759 } |
|
4760 } |
|
4761 else |
|
4762 { |
|
4763 $credits = $credits_parent; |
|
4764 } |
|
4765 |
|
4766 // DESCRIPTION |
|
4767 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'])) |
|
4768 { |
|
4769 $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4770 } |
|
4771 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'])) |
|
4772 { |
|
4773 $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4774 } |
|
4775 else |
|
4776 { |
|
4777 $description = $description_parent; |
|
4778 } |
|
4779 |
|
4780 // HASHES |
|
4781 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'])) |
|
4782 { |
|
4783 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash) |
|
4784 { |
|
4785 $value = null; |
|
4786 $algo = null; |
|
4787 if (isset($hash['data'])) |
|
4788 { |
|
4789 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4790 } |
|
4791 if (isset($hash['attribs']['']['algo'])) |
|
4792 { |
|
4793 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4794 } |
|
4795 else |
|
4796 { |
|
4797 $algo = 'md5'; |
|
4798 } |
|
4799 $hashes[] = $algo.':'.$value; |
|
4800 } |
|
4801 if (is_array($hashes)) |
|
4802 { |
|
4803 $hashes = array_values(SimplePie_Misc::array_unique($hashes)); |
|
4804 } |
|
4805 } |
|
4806 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'])) |
|
4807 { |
|
4808 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash) |
|
4809 { |
|
4810 $value = null; |
|
4811 $algo = null; |
|
4812 if (isset($hash['data'])) |
|
4813 { |
|
4814 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4815 } |
|
4816 if (isset($hash['attribs']['']['algo'])) |
|
4817 { |
|
4818 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4819 } |
|
4820 else |
|
4821 { |
|
4822 $algo = 'md5'; |
|
4823 } |
|
4824 $hashes[] = $algo.':'.$value; |
|
4825 } |
|
4826 if (is_array($hashes)) |
|
4827 { |
|
4828 $hashes = array_values(SimplePie_Misc::array_unique($hashes)); |
|
4829 } |
|
4830 } |
|
4831 else |
|
4832 { |
|
4833 $hashes = $hashes_parent; |
|
4834 } |
|
4835 |
|
4836 // KEYWORDS |
|
4837 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'])) |
|
4838 { |
|
4839 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'])) |
|
4840 { |
|
4841 $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); |
|
4842 foreach ($temp as $word) |
|
4843 { |
|
4844 $keywords[] = trim($word); |
|
4845 } |
|
4846 unset($temp); |
|
4847 } |
|
4848 if (is_array($keywords)) |
|
4849 { |
|
4850 $keywords = array_values(SimplePie_Misc::array_unique($keywords)); |
|
4851 } |
|
4852 } |
|
4853 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'])) |
|
4854 { |
|
4855 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'])) |
|
4856 { |
|
4857 $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); |
|
4858 foreach ($temp as $word) |
|
4859 { |
|
4860 $keywords[] = trim($word); |
|
4861 } |
|
4862 unset($temp); |
|
4863 } |
|
4864 if (is_array($keywords)) |
|
4865 { |
|
4866 $keywords = array_values(SimplePie_Misc::array_unique($keywords)); |
|
4867 } |
|
4868 } |
|
4869 else |
|
4870 { |
|
4871 $keywords = $keywords_parent; |
|
4872 } |
|
4873 |
|
4874 // PLAYER |
|
4875 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) |
|
4876 { |
|
4877 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
|
4878 } |
|
4879 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) |
|
4880 { |
|
4881 $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
|
4882 } |
|
4883 else |
|
4884 { |
|
4885 $player = $player_parent; |
|
4886 } |
|
4887 |
|
4888 // RATINGS |
|
4889 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'])) |
|
4890 { |
|
4891 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating) |
|
4892 { |
|
4893 $rating_scheme = null; |
|
4894 $rating_value = null; |
|
4895 if (isset($rating['attribs']['']['scheme'])) |
|
4896 { |
|
4897 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4898 } |
|
4899 else |
|
4900 { |
|
4901 $rating_scheme = 'urn:simple'; |
|
4902 } |
|
4903 if (isset($rating['data'])) |
|
4904 { |
|
4905 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4906 } |
|
4907 $ratings[] =& new $this->feed->rating_class($rating_scheme, $rating_value); |
|
4908 } |
|
4909 if (is_array($ratings)) |
|
4910 { |
|
4911 $ratings = array_values(SimplePie_Misc::array_unique($ratings)); |
|
4912 } |
|
4913 } |
|
4914 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'])) |
|
4915 { |
|
4916 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating) |
|
4917 { |
|
4918 $rating_scheme = null; |
|
4919 $rating_value = null; |
|
4920 if (isset($rating['attribs']['']['scheme'])) |
|
4921 { |
|
4922 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4923 } |
|
4924 else |
|
4925 { |
|
4926 $rating_scheme = 'urn:simple'; |
|
4927 } |
|
4928 if (isset($rating['data'])) |
|
4929 { |
|
4930 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4931 } |
|
4932 $ratings[] =& new $this->feed->rating_class($rating_scheme, $rating_value); |
|
4933 } |
|
4934 if (is_array($ratings)) |
|
4935 { |
|
4936 $ratings = array_values(SimplePie_Misc::array_unique($ratings)); |
|
4937 } |
|
4938 } |
|
4939 else |
|
4940 { |
|
4941 $ratings = $ratings_parent; |
|
4942 } |
|
4943 |
|
4944 // RESTRICTIONS |
|
4945 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'])) |
|
4946 { |
|
4947 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction) |
|
4948 { |
|
4949 $restriction_relationship = null; |
|
4950 $restriction_type = null; |
|
4951 $restriction_value = null; |
|
4952 if (isset($restriction['attribs']['']['relationship'])) |
|
4953 { |
|
4954 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4955 } |
|
4956 if (isset($restriction['attribs']['']['type'])) |
|
4957 { |
|
4958 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4959 } |
|
4960 if (isset($restriction['data'])) |
|
4961 { |
|
4962 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4963 } |
|
4964 $restrictions[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); |
|
4965 } |
|
4966 if (is_array($restrictions)) |
|
4967 { |
|
4968 $restrictions = array_values(SimplePie_Misc::array_unique($restrictions)); |
|
4969 } |
|
4970 } |
|
4971 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'])) |
|
4972 { |
|
4973 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction) |
|
4974 { |
|
4975 $restriction_relationship = null; |
|
4976 $restriction_type = null; |
|
4977 $restriction_value = null; |
|
4978 if (isset($restriction['attribs']['']['relationship'])) |
|
4979 { |
|
4980 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4981 } |
|
4982 if (isset($restriction['attribs']['']['type'])) |
|
4983 { |
|
4984 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4985 } |
|
4986 if (isset($restriction['data'])) |
|
4987 { |
|
4988 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
4989 } |
|
4990 $restrictions[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); |
|
4991 } |
|
4992 if (is_array($restrictions)) |
|
4993 { |
|
4994 $restrictions = array_values(SimplePie_Misc::array_unique($restrictions)); |
|
4995 } |
|
4996 } |
|
4997 else |
|
4998 { |
|
4999 $restrictions = $restrictions_parent; |
|
5000 } |
|
5001 |
|
5002 // THUMBNAILS |
|
5003 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'])) |
|
5004 { |
|
5005 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) |
|
5006 { |
|
5007 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
|
5008 } |
|
5009 if (is_array($thumbnails)) |
|
5010 { |
|
5011 $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails)); |
|
5012 } |
|
5013 } |
|
5014 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'])) |
|
5015 { |
|
5016 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) |
|
5017 { |
|
5018 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
|
5019 } |
|
5020 if (is_array($thumbnails)) |
|
5021 { |
|
5022 $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails)); |
|
5023 } |
|
5024 } |
|
5025 else |
|
5026 { |
|
5027 $thumbnails = $thumbnails_parent; |
|
5028 } |
|
5029 |
|
5030 // TITLES |
|
5031 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'])) |
|
5032 { |
|
5033 $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5034 } |
|
5035 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'])) |
|
5036 { |
|
5037 $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5038 } |
|
5039 else |
|
5040 { |
|
5041 $title = $title_parent; |
|
5042 } |
|
5043 |
|
5044 $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width); |
|
5045 } |
|
5046 } |
|
5047 } |
|
5048 |
|
5049 // If we have standalone media:content tags, loop through them. |
|
5050 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'])) |
|
5051 { |
|
5052 foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content) |
|
5053 { |
|
5054 if (isset($content['attribs']['']['url'])) |
|
5055 { |
|
5056 // Attributes |
|
5057 $bitrate = null; |
|
5058 $channels = null; |
|
5059 $duration = null; |
|
5060 $expression = null; |
|
5061 $framerate = null; |
|
5062 $height = null; |
|
5063 $javascript = null; |
|
5064 $lang = null; |
|
5065 $length = null; |
|
5066 $medium = null; |
|
5067 $samplingrate = null; |
|
5068 $type = null; |
|
5069 $url = null; |
|
5070 $width = null; |
|
5071 |
|
5072 // Elements |
|
5073 $captions = null; |
|
5074 $categories = null; |
|
5075 $copyrights = null; |
|
5076 $credits = null; |
|
5077 $description = null; |
|
5078 $hashes = null; |
|
5079 $keywords = null; |
|
5080 $player = null; |
|
5081 $ratings = null; |
|
5082 $restrictions = null; |
|
5083 $thumbnails = null; |
|
5084 $title = null; |
|
5085 |
|
5086 // Start checking the attributes of media:content |
|
5087 if (isset($content['attribs']['']['bitrate'])) |
|
5088 { |
|
5089 $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5090 } |
|
5091 if (isset($content['attribs']['']['channels'])) |
|
5092 { |
|
5093 $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5094 } |
|
5095 if (isset($content['attribs']['']['duration'])) |
|
5096 { |
|
5097 $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5098 } |
|
5099 else |
|
5100 { |
|
5101 $duration = $duration_parent; |
|
5102 } |
|
5103 if (isset($content['attribs']['']['expression'])) |
|
5104 { |
|
5105 $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5106 } |
|
5107 if (isset($content['attribs']['']['framerate'])) |
|
5108 { |
|
5109 $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5110 } |
|
5111 if (isset($content['attribs']['']['height'])) |
|
5112 { |
|
5113 $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5114 } |
|
5115 if (isset($content['attribs']['']['lang'])) |
|
5116 { |
|
5117 $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5118 } |
|
5119 if (isset($content['attribs']['']['fileSize'])) |
|
5120 { |
|
5121 $length = ceil($content['attribs']['']['fileSize']); |
|
5122 } |
|
5123 if (isset($content['attribs']['']['medium'])) |
|
5124 { |
|
5125 $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5126 } |
|
5127 if (isset($content['attribs']['']['samplingrate'])) |
|
5128 { |
|
5129 $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5130 } |
|
5131 if (isset($content['attribs']['']['type'])) |
|
5132 { |
|
5133 $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5134 } |
|
5135 if (isset($content['attribs']['']['width'])) |
|
5136 { |
|
5137 $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT); |
|
5138 } |
|
5139 $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); |
|
5140 |
|
5141 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel |
5154 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel |
5142 |
5155 |
5143 // CAPTIONS |
5156 // CAPTIONS |
5144 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) |
5157 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) |
5145 { |
5158 { |
11828 } |
11919 } |
11829 |
11920 |
11830 /** |
11921 /** |
11831 * Replace invalid character with percent encoding |
11922 * Replace invalid character with percent encoding |
11832 * |
11923 * |
11833 * @access private |
|
11834 * @param string $string Input string |
11924 * @param string $string Input string |
11835 * @param string $valid_chars Valid characters |
11925 * @param string $valid_chars Valid characters |
11836 * @param int $case Normalise case |
11926 * @param int $case Normalise case |
11837 * @return string |
11927 * @return string |
11838 */ |
11928 */ |
11839 function replace_invalid_with_pct_encoding($string, $valid_chars, $case = SIMPLEPIE_SAME_CASE) |
11929 function replace_invalid_with_pct_encoding($string, $valid_chars, $case = SIMPLEPIE_SAME_CASE, $iprivate = false) |
11840 { |
11930 { |
|
11931 // Normalize as many pct-encoded sections as possible |
|
11932 $string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array(&$this, 'remove_iunreserved_percent_encoded'), $string); |
|
11933 |
|
11934 // Replace invalid percent characters |
|
11935 $string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string); |
|
11936 |
|
11937 // Add unreserved and % to $valid_chars (the latter is safe because all |
|
11938 // pct-encoded sections are now valid). |
|
11939 $valid_chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%'; |
|
11940 |
|
11941 // Now replace any bytes that aren't allowed with their pct-encoded versions |
|
11942 $position = 0; |
|
11943 $strlen = strlen($string); |
|
11944 while (($position += strspn($string, $valid_chars, $position)) < $strlen) |
|
11945 { |
|
11946 $value = ord($string[$position]); |
|
11947 |
|
11948 // Start position |
|
11949 $start = $position; |
|
11950 |
|
11951 // By default we are valid |
|
11952 $valid = true; |
|
11953 |
|
11954 // No one byte sequences are valid due to the while. |
|
11955 // Two byte sequence: |
|
11956 if (($value & 0xE0) === 0xC0) |
|
11957 { |
|
11958 $character = ($value & 0x1F) << 6; |
|
11959 $length = 2; |
|
11960 $remaining = 1; |
|
11961 } |
|
11962 // Three byte sequence: |
|
11963 elseif (($value & 0xF0) === 0xE0) |
|
11964 { |
|
11965 $character = ($value & 0x0F) << 12; |
|
11966 $length = 3; |
|
11967 $remaining = 2; |
|
11968 } |
|
11969 // Four byte sequence: |
|
11970 elseif (($value & 0xF8) === 0xF0) |
|
11971 { |
|
11972 $character = ($value & 0x07) << 18; |
|
11973 $length = 4; |
|
11974 $remaining = 3; |
|
11975 } |
|
11976 // Invalid byte: |
|
11977 else |
|
11978 { |
|
11979 $valid = false; |
|
11980 $length = 1; |
|
11981 $remaining = 0; |
|
11982 } |
|
11983 |
|
11984 if ($remaining) |
|
11985 { |
|
11986 if ($position + $length <= $strlen) |
|
11987 { |
|
11988 for ($position++; $remaining; $position++) |
|
11989 { |
|
11990 $value = ord($string[$position]); |
|
11991 |
|
11992 // Check that the byte is valid, then add it to the character: |
|
11993 if (($value & 0xC0) === 0x80) |
|
11994 { |
|
11995 $character |= ($value & 0x3F) << (--$remaining * 6); |
|
11996 } |
|
11997 // If it is invalid, count the sequence as invalid and reprocess the current byte: |
|
11998 else |
|
11999 { |
|
12000 $valid = false; |
|
12001 $position--; |
|
12002 break; |
|
12003 } |
|
12004 } |
|
12005 } |
|
12006 else |
|
12007 { |
|
12008 $position = $strlen - 1; |
|
12009 $valid = false; |
|
12010 } |
|
12011 } |
|
12012 |
|
12013 // Percent encode anything invalid or not in ucschar |
|
12014 if ( |
|
12015 // Invalid sequences |
|
12016 !$valid |
|
12017 // Non-shortest form sequences are invalid |
|
12018 || $length > 1 && $character <= 0x7F |
|
12019 || $length > 2 && $character <= 0x7FF |
|
12020 || $length > 3 && $character <= 0xFFFF |
|
12021 // Outside of range of ucschar codepoints |
|
12022 // Noncharacters |
|
12023 || ($character & 0xFFFE) === 0xFFFE |
|
12024 || $character >= 0xFDD0 && $character <= 0xFDEF |
|
12025 || ( |
|
12026 // Everything else not in ucschar |
|
12027 $character > 0xD7FF && $character < 0xF900 |
|
12028 || $character < 0xA0 |
|
12029 || $character > 0xEFFFD |
|
12030 ) |
|
12031 && ( |
|
12032 // Everything not in iprivate, if it applies |
|
12033 !$iprivate |
|
12034 || $character < 0xE000 |
|
12035 || $character > 0x10FFFD |
|
12036 ) |
|
12037 ) |
|
12038 { |
|
12039 // If we were a character, pretend we weren't, but rather an error. |
|
12040 if ($valid) |
|
12041 $position--; |
|
12042 |
|
12043 for ($j = $start; $j <= $position; $j++) |
|
12044 { |
|
12045 $string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1); |
|
12046 $j += 2; |
|
12047 $position += 2; |
|
12048 $strlen += 2; |
|
12049 } |
|
12050 } |
|
12051 } |
|
12052 |
11841 // Normalise case |
12053 // Normalise case |
11842 if ($case & SIMPLEPIE_LOWERCASE) |
12054 if ($case & SIMPLEPIE_LOWERCASE) |
11843 { |
12055 { |
11844 $string = strtolower($string); |
12056 $string = strtolower($string); |
11845 } |
12057 } |
11846 elseif ($case & SIMPLEPIE_UPPERCASE) |
12058 elseif ($case & SIMPLEPIE_UPPERCASE) |
11847 { |
12059 { |
11848 $string = strtoupper($string); |
12060 $string = strtoupper($string); |
11849 } |
12061 } |
11850 |
12062 |
11851 // Store position and string length (to avoid constantly recalculating this) |
12063 return $string; |
11852 $position = 0; |
12064 } |
11853 $strlen = strlen($string); |
12065 |
11854 |
12066 /** |
11855 // Loop as long as we have invalid characters, advancing the position to the next invalid character |
12067 * Callback function for preg_replace_callback. |
11856 while (($position += strspn($string, $valid_chars, $position)) < $strlen) |
12068 * |
11857 { |
12069 * Removes sequences of percent encoded bytes that represent UTF-8 |
11858 // If we have a % character |
12070 * encoded characters in iunreserved |
11859 if ($string[$position] === '%') |
12071 * |
11860 { |
12072 * @access private |
11861 // If we have a pct-encoded section |
12073 * @param array $match PCRE match |
11862 if ($position + 2 < $strlen && strspn($string, '0123456789ABCDEFabcdef', $position + 1, 2) === 2) |
12074 * @return string Replacement |
11863 { |
12075 */ |
11864 // Get the the represented character |
12076 function remove_iunreserved_percent_encoded($match) |
11865 $chr = chr(hexdec(substr($string, $position + 1, 2))); |
12077 { |
11866 |
12078 // As we just have valid percent encoded sequences we can just explode |
11867 // If the character is valid, replace the pct-encoded with the actual character while normalising case |
12079 // and ignore the first member of the returned array (an empty string). |
11868 if (strpos($valid_chars, $chr) !== false) |
12080 $bytes = explode('%', $match[0]); |
|
12081 |
|
12082 // Initialize the new string (this is what will be returned) and that |
|
12083 // there are no bytes remaining in the current sequence (unsurprising |
|
12084 // at the first byte!). |
|
12085 $string = ''; |
|
12086 $remaining = 0; |
|
12087 |
|
12088 // Loop over each and every byte, and set $value to its value |
|
12089 for ($i = 1, $len = count($bytes); $i < $len; $i++) |
|
12090 { |
|
12091 $value = hexdec($bytes[$i]); |
|
12092 |
|
12093 // If we're the first byte of sequence: |
|
12094 if (!$remaining) |
|
12095 { |
|
12096 // Start position |
|
12097 $start = $i; |
|
12098 |
|
12099 // By default we are valid |
|
12100 $valid = true; |
|
12101 |
|
12102 // One byte sequence: |
|
12103 if ($value <= 0x7F) |
|
12104 { |
|
12105 $character = $value; |
|
12106 $length = 1; |
|
12107 } |
|
12108 // Two byte sequence: |
|
12109 elseif (($value & 0xE0) === 0xC0) |
|
12110 { |
|
12111 $character = ($value & 0x1F) << 6; |
|
12112 $length = 2; |
|
12113 $remaining = 1; |
|
12114 } |
|
12115 // Three byte sequence: |
|
12116 elseif (($value & 0xF0) === 0xE0) |
|
12117 { |
|
12118 $character = ($value & 0x0F) << 12; |
|
12119 $length = 3; |
|
12120 $remaining = 2; |
|
12121 } |
|
12122 // Four byte sequence: |
|
12123 elseif (($value & 0xF8) === 0xF0) |
|
12124 { |
|
12125 $character = ($value & 0x07) << 18; |
|
12126 $length = 4; |
|
12127 $remaining = 3; |
|
12128 } |
|
12129 // Invalid byte: |
|
12130 else |
|
12131 { |
|
12132 $valid = false; |
|
12133 $remaining = 0; |
|
12134 } |
|
12135 } |
|
12136 // Continuation byte: |
|
12137 else |
|
12138 { |
|
12139 // Check that the byte is valid, then add it to the character: |
|
12140 if (($value & 0xC0) === 0x80) |
|
12141 { |
|
12142 $remaining--; |
|
12143 $character |= ($value & 0x3F) << ($remaining * 6); |
|
12144 } |
|
12145 // If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence: |
|
12146 else |
|
12147 { |
|
12148 $valid = false; |
|
12149 $remaining = 0; |
|
12150 $i--; |
|
12151 } |
|
12152 } |
|
12153 |
|
12154 // If we've reached the end of the current byte sequence, append it to Unicode::$data |
|
12155 if (!$remaining) |
|
12156 { |
|
12157 // Percent encode anything invalid or not in iunreserved |
|
12158 if ( |
|
12159 // Invalid sequences |
|
12160 !$valid |
|
12161 // Non-shortest form sequences are invalid |
|
12162 || $length > 1 && $character <= 0x7F |
|
12163 || $length > 2 && $character <= 0x7FF |
|
12164 || $length > 3 && $character <= 0xFFFF |
|
12165 // Outside of range of iunreserved codepoints |
|
12166 || $character < 0x2D |
|
12167 || $character > 0xEFFFD |
|
12168 // Noncharacters |
|
12169 || ($character & 0xFFFE) === 0xFFFE |
|
12170 || $character >= 0xFDD0 && $character <= 0xFDEF |
|
12171 // Everything else not in iunreserved (this is all BMP) |
|
12172 || $character === 0x2F |
|
12173 || $character > 0x39 && $character < 0x41 |
|
12174 || $character > 0x5A && $character < 0x61 |
|
12175 || $character > 0x7A && $character < 0x7E |
|
12176 || $character > 0x7E && $character < 0xA0 |
|
12177 || $character > 0xD7FF && $character < 0xF900 |
|
12178 ) |
|
12179 { |
|
12180 for ($j = $start; $j <= $i; $j++) |
11869 { |
12181 { |
11870 if ($case & SIMPLEPIE_LOWERCASE) |
12182 $string .= '%' . strtoupper($bytes[$j]); |
11871 { |
|
11872 $chr = strtolower($chr); |
|
11873 } |
|
11874 elseif ($case & SIMPLEPIE_UPPERCASE) |
|
11875 { |
|
11876 $chr = strtoupper($chr); |
|
11877 } |
|
11878 $string = substr_replace($string, $chr, $position, 3); |
|
11879 $strlen -= 2; |
|
11880 $position++; |
|
11881 } |
12183 } |
11882 |
12184 } |
11883 // Otherwise just normalise the pct-encoded to uppercase |
12185 else |
11884 else |
12186 { |
|
12187 for ($j = $start; $j <= $i; $j++) |
11885 { |
12188 { |
11886 $string = substr_replace($string, strtoupper(substr($string, $position + 1, 2)), $position + 1, 2); |
12189 $string .= chr(hexdec($bytes[$j])); |
11887 $position += 3; |
|
11888 } |
12190 } |
11889 } |
12191 } |
11890 // If we don't have a pct-encoded section, just replace the % with its own esccaped form |
12192 } |
11891 else |
12193 } |
11892 { |
12194 |
11893 $string = substr_replace($string, '%25', $position, 1); |
12195 // If we have any bytes left over they are invalid (i.e., we are |
11894 $strlen += 2; |
12196 // mid-way through a multi-byte sequence) |
11895 $position += 3; |
12197 if ($remaining) |
11896 } |
12198 { |
11897 } |
12199 for ($j = $start; $j < $len; $j++) |
11898 // If we have an invalid character, change into its pct-encoded form |
12200 { |
11899 else |
12201 $string .= '%' . strtoupper($bytes[$j]); |
11900 { |
12202 } |
11901 $replacement = sprintf("%%%02X", ord($string[$position])); |
12203 } |
11902 $string = str_replace($string[$position], $replacement, $string); |
12204 |
11903 $strlen = strlen($string); |
|
11904 } |
|
11905 } |
|
11906 return $string; |
12205 return $string; |
11907 } |
12206 } |
11908 |
12207 |
11909 /** |
12208 /** |
11910 * Check if the object represents a valid IRI |
12209 * Check if the object represents a valid IRI |