Enclosure.php 26.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
<?php
/**
 * SimplePie
 *
 * A PHP-Based RSS and Atom Feed Framework.
 * Takes the hard work out of managing a complete RSS/Atom solution.
 *
 * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 * 	* Redistributions of source code must retain the above copyright notice, this list of
 * 	  conditions and the following disclaimer.
 *
 * 	* Redistributions in binary form must reproduce the above copyright notice, this list
 * 	  of conditions and the following disclaimer in the documentation and/or other materials
 * 	  provided with the distribution.
 *
 * 	* Neither the name of the SimplePie Team nor the names of its contributors may be used
 * 	  to endorse or promote products derived from this software without specific prior
 * 	  written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @package SimplePie
 * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
 * @author Ryan Parman
 * @author Sam Sneddon
 * @author Ryan McCue
 * @link http://simplepie.org/ SimplePie
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
 */

/**
 * Handles everything related to enclosures (including Media RSS and iTunes RSS)
 *
 * Used by {@see SimplePie_Item::get_enclosure()} and {@see SimplePie_Item::get_enclosures()}
 *
 * This class can be overloaded with {@see SimplePie::set_enclosure_class()}
 *
 * @package SimplePie
 * @subpackage API
 */
class SimplePie_Enclosure
{
	/**
	 * @var string
	 * @see get_bitrate()
	 */
	var $bitrate;

	/**
	 * @var array
	 * @see get_captions()
	 */
	var $captions;

	/**
	 * @var array
	 * @see get_categories()
	 */
	var $categories;

	/**
	 * @var int
	 * @see get_channels()
	 */
	var $channels;

	/**
	 * @var SimplePie_Copyright
	 * @see get_copyright()
	 */
	var $copyright;

	/**
	 * @var array
	 * @see get_credits()
	 */
	var $credits;

	/**
	 * @var string
	 * @see get_description()
	 */
	var $description;

	/**
	 * @var int
	 * @see get_duration()
	 */
	var $duration;

	/**
	 * @var string
	 * @see get_expression()
	 */
	var $expression;

	/**
	 * @var string
	 * @see get_framerate()
	 */
	var $framerate;

	/**
	 * @var string
	 * @see get_handler()
	 */
	var $handler;

	/**
	 * @var array
	 * @see get_hashes()
	 */
	var $hashes;

	/**
	 * @var string
	 * @see get_height()
	 */
	var $height;

	/**
	 * @deprecated
	 * @var null
	 */
	var $javascript;

	/**
	 * @var array
	 * @see get_keywords()
	 */
	var $keywords;

	/**
	 * @var string
	 * @see get_language()
	 */
	var $lang;

	/**
	 * @var string
	 * @see get_length()
	 */
	var $length;

	/**
	 * @var string
	 * @see get_link()
	 */
	var $link;

	/**
	 * @var string
	 * @see get_medium()
	 */
	var $medium;

	/**
	 * @var string
	 * @see get_player()
	 */
	var $player;

	/**
	 * @var array
	 * @see get_ratings()
	 */
	var $ratings;

	/**
	 * @var array
	 * @see get_restrictions()
	 */
	var $restrictions;

	/**
	 * @var string
	 * @see get_sampling_rate()
	 */
	var $samplingrate;

	/**
	 * @var array
	 * @see get_thumbnails()
	 */
	var $thumbnails;

	/**
	 * @var string
	 * @see get_title()
	 */
	var $title;

	/**
	 * @var string
	 * @see get_type()
	 */
	var $type;

	/**
	 * @var string
	 * @see get_width()
	 */
	var $width;

	/**
	 * Constructor, used to input the data
	 *
	 * For documentation on all the parameters, see the corresponding
	 * properties and their accessors
	 *
	 * @uses idna_convert If available, this will convert an IDN
	 */
	public function __construct($link = null, $type = null, $length = null, $javascript = null, $bitrate = null, $captions = null, $categories = null, $channels = null, $copyright = null, $credits = null, $description = null, $duration = null, $expression = null, $framerate = null, $hashes = null, $height = null, $keywords = null, $lang = null, $medium = null, $player = null, $ratings = null, $restrictions = null, $samplingrate = null, $thumbnails = null, $title = null, $width = null)
	{
		$this->bitrate = $bitrate;
		$this->captions = $captions;
		$this->categories = $categories;
		$this->channels = $channels;
		$this->copyright = $copyright;
		$this->credits = $credits;
		$this->description = $description;
		$this->duration = $duration;
		$this->expression = $expression;
		$this->framerate = $framerate;
		$this->hashes = $hashes;
		$this->height = $height;
		$this->keywords = $keywords;
		$this->lang = $lang;
		$this->length = $length;
		$this->link = $link;
		$this->medium = $medium;
		$this->player = $player;
		$this->ratings = $ratings;
		$this->restrictions = $restrictions;
		$this->samplingrate = $samplingrate;
		$this->thumbnails = $thumbnails;
		$this->title = $title;
		$this->type = $type;
		$this->width = $width;

		if (class_exists('idna_convert'))
		{
			$idn = new idna_convert();
			$parsed = SimplePie_Misc::parse_url($link);
			$this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
		}
		$this->handler = $this->get_handler(); // Needs to load last
	}

	/**
	 * String-ified version
	 *
	 * @return string
	 */
	public function __toString()
	{
		// There is no $this->data here
		return md5(serialize($this));
	}

	/**
	 * Get the bitrate
	 *
	 * @return string|null
	 */
	public function get_bitrate()
	{
		if ($this->bitrate !== null)
		{
			return $this->bitrate;
		}

		return null;
	}

	/**
	 * Get a single caption
	 *
	 * @param int $key
	 * @return SimplePie_Caption|null
	 */
	public function get_caption($key = 0)
	{
		$captions = $this->get_captions();
		if (isset($captions[$key]))
		{
			return $captions[$key];
		}

		return null;
	}

	/**
	 * Get all captions
	 *
	 * @return array|null Array of {@see SimplePie_Caption} objects
	 */
	public function get_captions()
	{
		if ($this->captions !== null)
		{
			return $this->captions;
		}

		return null;
	}

	/**
	 * Get a single category
	 *
	 * @param int $key
	 * @return SimplePie_Category|null
	 */
	public function get_category($key = 0)
	{
		$categories = $this->get_categories();
		if (isset($categories[$key]))
		{
			return $categories[$key];
		}

		return null;
	}

	/**
	 * Get all categories
	 *
	 * @return array|null Array of {@see SimplePie_Category} objects
	 */
	public function get_categories()
	{
		if ($this->categories !== null)
		{
			return $this->categories;
		}

		return null;
	}

	/**
	 * Get the number of audio channels
	 *
	 * @return int|null
	 */
	public function get_channels()
	{
		if ($this->channels !== null)
		{
			return $this->channels;
		}

		return null;
	}

	/**
	 * Get the copyright information
	 *
	 * @return SimplePie_Copyright|null
	 */
	public function get_copyright()
	{
		if ($this->copyright !== null)
		{
			return $this->copyright;
		}

		return null;
	}

	/**
	 * Get a single credit
	 *
	 * @param int $key
	 * @return SimplePie_Credit|null
	 */
	public function get_credit($key = 0)
	{
		$credits = $this->get_credits();
		if (isset($credits[$key]))
		{
			return $credits[$key];
		}

		return null;
	}

	/**
	 * Get all credits
	 *
	 * @return array|null Array of {@see SimplePie_Credit} objects
	 */
	public function get_credits()
	{
		if ($this->credits !== null)
		{
			return $this->credits;
		}

		return null;
	}

	/**
	 * Get the description of the enclosure
	 *
	 * @return string|null
	 */
	public function get_description()
	{
		if ($this->description !== null)
		{
			return $this->description;
		}

		return null;
	}

	/**
	 * Get the duration of the enclosure
	 *
	 * @param bool $convert Convert seconds into hh:mm:ss
	 * @return string|int|null 'hh:mm:ss' string if `$convert` was specified, otherwise integer (or null if none found)
	 */
	public function get_duration($convert = false)
	{
		if ($this->duration !== null)
		{
			if ($convert)
			{
				$time = SimplePie_Misc::time_hms($this->duration);
				return $time;
			}

			return $this->duration;
		}

		return null;
	}

	/**
	 * Get the expression
	 *
	 * @return string Probably one of 'sample', 'full', 'nonstop', 'clip'. Defaults to 'full'
	 */
	public function get_expression()
	{
		if ($this->expression !== null)
		{
			return $this->expression;
		}

		return 'full';
	}

	/**
	 * Get the file extension
	 *
	 * @return string|null
	 */
	public function get_extension()
	{
		if ($this->link !== null)
		{
			$url = SimplePie_Misc::parse_url($this->link);
			if ($url['path'] !== '')
			{
				return pathinfo($url['path'], PATHINFO_EXTENSION);
			}
		}
		return null;
	}

	/**
	 * Get the framerate (in frames-per-second)
	 *
	 * @return string|null
	 */
	public function get_framerate()
	{
		if ($this->framerate !== null)
		{
			return $this->framerate;
		}

		return null;
	}

	/**
	 * Get the preferred handler
	 *
	 * @return string|null One of 'flash', 'fmedia', 'quicktime', 'wmedia', 'mp3'
	 */
	public function get_handler()
	{
		return $this->get_real_type(true);
	}

	/**
	 * Get a single hash
	 *
	 * @link http://www.rssboard.org/media-rss#media-hash
	 * @param int $key
	 * @return string|null Hash as per `media:hash`, prefixed with "$algo:"
	 */
	public function get_hash($key = 0)
	{
		$hashes = $this->get_hashes();
		if (isset($hashes[$key]))
		{
			return $hashes[$key];
		}

		return null;
	}

	/**
	 * Get all credits
	 *
	 * @return array|null Array of strings, see {@see get_hash()}
	 */
	public function get_hashes()
	{
		if ($this->hashes !== null)
		{
			return $this->hashes;
		}

		return null;
	}

	/**
	 * Get the height
	 *
	 * @return string|null
	 */
	public function get_height()
	{
		if ($this->height !== null)
		{
			return $this->height;
		}

		return null;
	}

	/**
	 * Get the language
	 *
	 * @link http://tools.ietf.org/html/rfc3066
	 * @return string|null Language code as per RFC 3066
	 */
	public function get_language()
	{
		if ($this->lang !== null)
		{
			return $this->lang;
		}

		return null;
	}

	/**
	 * Get a single keyword
	 *
	 * @param int $key
	 * @return string|null
	 */
	public function get_keyword($key = 0)
	{
		$keywords = $this->get_keywords();
		if (isset($keywords[$key]))
		{
			return $keywords[$key];
		}

		return null;
	}

	/**
	 * Get all keywords
	 *
	 * @return array|null Array of strings
	 */
	public function get_keywords()
	{
		if ($this->keywords !== null)
		{
			return $this->keywords;
		}

		return null;
	}

	/**
	 * Get length
	 *
	 * @return float Length in bytes
	 */
	public function get_length()
	{
		if ($this->length !== null)
		{
			return $this->length;
		}

		return null;
	}

	/**
	 * Get the URL
	 *
	 * @return string|null
	 */
	public function get_link()
	{
		if ($this->link !== null)
		{
			return urldecode($this->link);
		}

		return null;
	}

	/**
	 * Get the medium
	 *
	 * @link http://www.rssboard.org/media-rss#media-content
	 * @return string|null Should be one of 'image', 'audio', 'video', 'document', 'executable'
	 */
	public function get_medium()
	{
		if ($this->medium !== null)
		{
			return $this->medium;
		}

		return null;
	}

	/**
	 * Get the player URL
	 *
	 * Typically the same as {@see get_permalink()}
	 * @return string|null Player URL
	 */
	public function get_player()
	{
		if ($this->player !== null)
		{
			return $this->player;
		}

		return null;
	}

	/**
	 * Get a single rating
	 *
	 * @param int $key
	 * @return SimplePie_Rating|null
	 */
	public function get_rating($key = 0)
	{
		$ratings = $this->get_ratings();
		if (isset($ratings[$key]))
		{
			return $ratings[$key];
		}

		return null;
	}

	/**
	 * Get all ratings
	 *
	 * @return array|null Array of {@see SimplePie_Rating} objects
	 */
	public function get_ratings()
	{
		if ($this->ratings !== null)
		{
			return $this->ratings;
		}

		return null;
	}

	/**
	 * Get a single restriction
	 *
	 * @param int $key
	 * @return SimplePie_Restriction|null
	 */
	public function get_restriction($key = 0)
	{
		$restrictions = $this->get_restrictions();
		if (isset($restrictions[$key]))
		{
			return $restrictions[$key];
		}

		return null;
	}

	/**
	 * Get all restrictions
	 *
	 * @return array|null Array of {@see SimplePie_Restriction} objects
	 */
	public function get_restrictions()
	{
		if ($this->restrictions !== null)
		{
			return $this->restrictions;
		}

		return null;
	}

	/**
	 * Get the sampling rate (in kHz)
	 *
	 * @return string|null
	 */
	public function get_sampling_rate()
	{
		if ($this->samplingrate !== null)
		{
			return $this->samplingrate;
		}

		return null;
	}

	/**
	 * Get the file size (in MiB)
	 *
	 * @return float|null File size in mebibytes (1048 bytes)
	 */
	public function get_size()
	{
		$length = $this->get_length();
		if ($length !== null)
		{
			return round($length/1048576, 2);
		}

		return null;
	}

	/**
	 * Get a single thumbnail
	 *
	 * @param int $key
	 * @return string|null Thumbnail URL
	 */
	public function get_thumbnail($key = 0)
	{
		$thumbnails = $this->get_thumbnails();
		if (isset($thumbnails[$key]))
		{
			return $thumbnails[$key];
		}

		return null;
	}

	/**
	 * Get all thumbnails
	 *
	 * @return array|null Array of thumbnail URLs
	 */
	public function get_thumbnails()
	{
		if ($this->thumbnails !== null)
		{
			return $this->thumbnails;
		}

		return null;
	}

	/**
	 * Get the title
	 *
	 * @return string|null
	 */
	public function get_title()
	{
		if ($this->title !== null)
		{
			return $this->title;
		}

		return null;
	}

	/**
	 * Get mimetype of the enclosure
	 *
	 * @see get_real_type()
	 * @return string|null MIME type
	 */
	public function get_type()
	{
		if ($this->type !== null)
		{
			return $this->type;
		}

		return null;
	}

	/**
	 * Get the width
	 *
	 * @return string|null
	 */
	public function get_width()
	{
		if ($this->width !== null)
		{
			return $this->width;
		}

		return null;
	}

	/**
	 * Embed the enclosure using `<embed>`
	 *
	 * @deprecated Use the second parameter to {@see embed} instead
	 *
	 * @param array|string $options See first paramter to {@see embed}
	 * @return string HTML string to output
	 */
	public function native_embed($options='')
	{
		return $this->embed($options, true);
	}

	/**
	 * Embed the enclosure using Javascript
	 *
	 * `$options` is an array or comma-separated key:value string, with the
	 * following properties:
	 *
	 * - `alt` (string): Alternate content for when an end-user does not have
	 *    the appropriate handler installed or when a file type is
	 *    unsupported. Can be any text or HTML. Defaults to blank.
	 * - `altclass` (string): If a file type is unsupported, the end-user will
	 *    see the alt text (above) linked directly to the content. That link
	 *    will have this value as its class name. Defaults to blank.
	 * - `audio` (string): This is an image that should be used as a
	 *    placeholder for audio files before they're loaded (QuickTime-only).
	 *    Can be any relative or absolute URL. Defaults to blank.
	 * - `bgcolor` (string): The background color for the media, if not
	 *    already transparent. Defaults to `#ffffff`.
	 * - `height` (integer): The height of the embedded media. Accepts any
	 *    numeric pixel value (such as `360`) or `auto`. Defaults to `auto`,
	 *    and it is recommended that you use this default.
	 * - `loop` (boolean): Do you want the media to loop when it's done?
	 *    Defaults to `false`.
	 * - `mediaplayer` (string): The location of the included
	 *    `mediaplayer.swf` file. This allows for the playback of Flash Video
	 *    (`.flv`) files, and is the default handler for non-Odeo MP3's.
	 *    Defaults to blank.
	 * - `video` (string): This is an image that should be used as a
	 *    placeholder for video files before they're loaded (QuickTime-only).
	 *    Can be any relative or absolute URL. Defaults to blank.
	 * - `width` (integer): The width of the embedded media. Accepts any
	 *    numeric pixel value (such as `480`) or `auto`. Defaults to `auto`,
	 *    and it is recommended that you use this default.
	 * - `widescreen` (boolean): Is the enclosure widescreen or standard?
	 *    This applies only to video enclosures, and will automatically resize
	 *    the content appropriately.  Defaults to `false`, implying 4:3 mode.
	 *
	 * Note: Non-widescreen (4:3) mode with `width` and `height` set to `auto`
	 * will default to 480x360 video resolution.  Widescreen (16:9) mode with
	 * `width` and `height` set to `auto` will default to 480x270 video resolution.
	 *
	 * @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'.
	 * @param array|string $options Comma-separated key:value list, or array
	 * @param bool $native Use `<embed>`
	 * @return string HTML string to output
	 */
	public function embed($options = '', $native = false)
	{
		// Set up defaults
		$audio = '';
		$video = '';
		$alt = '';
		$altclass = '';
		$loop = 'false';
		$width = 'auto';
		$height = 'auto';
		$bgcolor = '#ffffff';
		$mediaplayer = '';
		$widescreen = false;
		$handler = $this->get_handler();
		$type = $this->get_real_type();

		// Process options and reassign values as necessary
		if (is_array($options))
		{
			extract($options);
		}
		else
		{
			$options = explode(',', $options);
			foreach($options as $option)
			{
				$opt = explode(':', $option, 2);
				if (isset($opt[0], $opt[1]))
				{
					$opt[0] = trim($opt[0]);
					$opt[1] = trim($opt[1]);
					switch ($opt[0])
					{
						case 'audio':
							$audio = $opt[1];
							break;

						case 'video':
							$video = $opt[1];
							break;

						case 'alt':
							$alt = $opt[1];
							break;

						case 'altclass':
							$altclass = $opt[1];
							break;

						case 'loop':
							$loop = $opt[1];
							break;

						case 'width':
							$width = $opt[1];
							break;

						case 'height':
							$height = $opt[1];
							break;

						case 'bgcolor':
							$bgcolor = $opt[1];
							break;

						case 'mediaplayer':
							$mediaplayer = $opt[1];
							break;

						case 'widescreen':
							$widescreen = $opt[1];
							break;
					}
				}
			}
		}

		$mime = explode('/', $type, 2);
		$mime = $mime[0];

		// Process values for 'auto'
		if ($width === 'auto')
		{
			if ($mime === 'video')
			{
				if ($height === 'auto')
				{
					$width = 480;
				}
				elseif ($widescreen)
				{
					$width = round((intval($height)/9)*16);
				}
				else
				{
					$width = round((intval($height)/3)*4);
				}
			}
			else
			{
				$width = '100%';
			}
		}

		if ($height === 'auto')
		{
			if ($mime === 'audio')
			{
				$height = 0;
			}
			elseif ($mime === 'video')
			{
				if ($width === 'auto')
				{
					if ($widescreen)
					{
						$height = 270;
					}
					else
					{
						$height = 360;
					}
				}
				elseif ($widescreen)
				{
					$height = round((intval($width)/16)*9);
				}
				else
				{
					$height = round((intval($width)/4)*3);
				}
			}
			else
			{
				$height = 376;
			}
		}
		elseif ($mime === 'audio')
		{
			$height = 0;
		}

		// Set proper placeholder value
		if ($mime === 'audio')
		{
			$placeholder = $audio;
		}
		elseif ($mime === 'video')
		{
			$placeholder = $video;
		}

		$embed = '';

		// Flash
		if ($handler === 'flash')
		{
			if ($native)
			{
				$embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>";
			}
			else
			{
				$embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
			}
		}

		// Flash Media Player file types.
		// Preferred handler for MP3 file types.
		elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== ''))
		{
			$height += 20;
			if ($native)
			{
				$embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>";
			}
			else
			{
				$embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
			}
		}

		// QuickTime 7 file types.  Need to test with QuickTime 6.
		// Only handle MP3's if the Flash Media Player is not present.
		elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === ''))
		{
			$height += 16;
			if ($native)
			{
				if ($placeholder !== '')
				{
					$embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"" . $this->get_link() . "\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>";
				}
				else
				{
					$embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"" . $this->get_link() . "\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>";
				}
			}
			else
			{
				$embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
			}
		}

		// Windows Media
		elseif ($handler === 'wmedia')
		{
			$height += 45;
			if ($native)
			{
				$embed .= "<embed type=\"application/x-mplayer2\" src=\"" . $this->get_link() . "\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>";
			}
			else
			{
				$embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
			}
		}

		// Everything else
		else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';

		return $embed;
	}

	/**
	 * Get the real media type
	 *
	 * Often, feeds lie to us, necessitating a bit of deeper inspection. This
	 * converts types to their canonical representations based on the file
	 * extension
	 *
	 * @see get_type()
	 * @param bool $find_handler Internal use only, use {@see get_handler()} instead
	 * @return string MIME type
	 */
	public function get_real_type($find_handler = false)
	{
		// Mime-types by handler.
		$types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
		$types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player
		$types_quicktime = array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mp4', 'audio/m4a', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'video/3gpp', 'video/3gpp2', 'video/m4v', 'video/x-m4v', 'video/mp4', 'video/mpeg', 'video/x-mpeg', 'video/quicktime', 'video/sd-video'); // QuickTime
		$types_wmedia = array('application/asx', 'application/x-mplayer2', 'audio/x-ms-wma', 'audio/x-ms-wax', 'video/x-ms-asf-plugin', 'video/x-ms-asf', 'video/x-ms-wm', 'video/x-ms-wmv', 'video/x-ms-wvx'); // Windows Media
		$types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3

		if ($this->get_type() !== null)
		{
			$type = strtolower($this->type);
		}
		else
		{
			$type = null;
		}

		// If we encounter an unsupported mime-type, check the file extension and guess intelligently.
		if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
		{
			$extension = $this->get_extension();
			if ($extension === null) {
				return null;
			}

			switch (strtolower($extension))
			{
				// Audio mime-types
				case 'aac':
				case 'adts':
					$type = 'audio/acc';
					break;

				case 'aif':
				case 'aifc':
				case 'aiff':
				case 'cdda':
					$type = 'audio/aiff';
					break;

				case 'bwf':
					$type = 'audio/wav';
					break;

				case 'kar':
				case 'mid':
				case 'midi':
				case 'smf':
					$type = 'audio/midi';
					break;

				case 'm4a':
					$type = 'audio/x-m4a';
					break;

				case 'mp3':
				case 'swa':
					$type = 'audio/mp3';
					break;

				case 'wav':
					$type = 'audio/wav';
					break;

				case 'wax':
					$type = 'audio/x-ms-wax';
					break;

				case 'wma':
					$type = 'audio/x-ms-wma';
					break;

				// Video mime-types
				case '3gp':
				case '3gpp':
					$type = 'video/3gpp';
					break;

				case '3g2':
				case '3gp2':
					$type = 'video/3gpp2';
					break;

				case 'asf':
					$type = 'video/x-ms-asf';
					break;

				case 'flv':
					$type = 'video/x-flv';
					break;

				case 'm1a':
				case 'm1s':
				case 'm1v':
				case 'm15':
				case 'm75':
				case 'mp2':
				case 'mpa':
				case 'mpeg':
				case 'mpg':
				case 'mpm':
				case 'mpv':
					$type = 'video/mpeg';
					break;

				case 'm4v':
					$type = 'video/x-m4v';
					break;

				case 'mov':
				case 'qt':
					$type = 'video/quicktime';
					break;

				case 'mp4':
				case 'mpg4':
					$type = 'video/mp4';
					break;

				case 'sdv':
					$type = 'video/sd-video';
					break;

				case 'wm':
					$type = 'video/x-ms-wm';
					break;

				case 'wmv':
					$type = 'video/x-ms-wmv';
					break;

				case 'wvx':
					$type = 'video/x-ms-wvx';
					break;

				// Flash mime-types
				case 'spl':
					$type = 'application/futuresplash';
					break;

				case 'swf':
					$type = 'application/x-shockwave-flash';
					break;
			}
		}

		if ($find_handler)
		{
			if (in_array($type, $types_flash))
			{
				return 'flash';
			}
			elseif (in_array($type, $types_fmedia))
			{
				return 'fmedia';
			}
			elseif (in_array($type, $types_quicktime))
			{
				return 'quicktime';
			}
			elseif (in_array($type, $types_wmedia))
			{
				return 'wmedia';
			}
			elseif (in_array($type, $types_mp3))
			{
				return 'mp3';
			}

			return null;
		}

		return $type;
	}
}