PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/wp-includes/SimplePie/Enclosure.php

https://bitbucket.org/dkrzos/phc
PHP | 1380 lines | 816 code | 116 blank | 448 comment | 65 complexity | 122e861f42eb6e01ce8d4b0f11fb735d MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * SimplePie
  4. *
  5. * A PHP-Based RSS and Atom Feed Framework.
  6. * Takes the hard work out of managing a complete RSS/Atom solution.
  7. *
  8. * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification, are
  12. * permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright notice, this list of
  15. * conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright notice, this list
  18. * of conditions and the following disclaimer in the documentation and/or other materials
  19. * provided with the distribution.
  20. *
  21. * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  22. * to endorse or promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  27. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  28. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * @package SimplePie
  36. * @version 1.3.1
  37. * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
  38. * @author Ryan Parman
  39. * @author Geoffrey Sneddon
  40. * @author Ryan McCue
  41. * @link http://simplepie.org/ SimplePie
  42. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  43. */
  44. /**
  45. * Handles everything related to enclosures (including Media RSS and iTunes RSS)
  46. *
  47. * Used by {@see SimplePie_Item::get_enclosure()} and {@see SimplePie_Item::get_enclosures()}
  48. *
  49. * This class can be overloaded with {@see SimplePie::set_enclosure_class()}
  50. *
  51. * @package SimplePie
  52. * @subpackage API
  53. */
  54. class SimplePie_Enclosure
  55. {
  56. /**
  57. * @var string
  58. * @see get_bitrate()
  59. */
  60. var $bitrate;
  61. /**
  62. * @var array
  63. * @see get_captions()
  64. */
  65. var $captions;
  66. /**
  67. * @var array
  68. * @see get_categories()
  69. */
  70. var $categories;
  71. /**
  72. * @var int
  73. * @see get_channels()
  74. */
  75. var $channels;
  76. /**
  77. * @var SimplePie_Copyright
  78. * @see get_copyright()
  79. */
  80. var $copyright;
  81. /**
  82. * @var array
  83. * @see get_credits()
  84. */
  85. var $credits;
  86. /**
  87. * @var string
  88. * @see get_description()
  89. */
  90. var $description;
  91. /**
  92. * @var int
  93. * @see get_duration()
  94. */
  95. var $duration;
  96. /**
  97. * @var string
  98. * @see get_expression()
  99. */
  100. var $expression;
  101. /**
  102. * @var string
  103. * @see get_framerate()
  104. */
  105. var $framerate;
  106. /**
  107. * @var string
  108. * @see get_handler()
  109. */
  110. var $handler;
  111. /**
  112. * @var array
  113. * @see get_hashes()
  114. */
  115. var $hashes;
  116. /**
  117. * @var string
  118. * @see get_height()
  119. */
  120. var $height;
  121. /**
  122. * @deprecated
  123. * @var null
  124. */
  125. var $javascript;
  126. /**
  127. * @var array
  128. * @see get_keywords()
  129. */
  130. var $keywords;
  131. /**
  132. * @var string
  133. * @see get_language()
  134. */
  135. var $lang;
  136. /**
  137. * @var string
  138. * @see get_length()
  139. */
  140. var $length;
  141. /**
  142. * @var string
  143. * @see get_link()
  144. */
  145. var $link;
  146. /**
  147. * @var string
  148. * @see get_medium()
  149. */
  150. var $medium;
  151. /**
  152. * @var string
  153. * @see get_player()
  154. */
  155. var $player;
  156. /**
  157. * @var array
  158. * @see get_ratings()
  159. */
  160. var $ratings;
  161. /**
  162. * @var array
  163. * @see get_restrictions()
  164. */
  165. var $restrictions;
  166. /**
  167. * @var string
  168. * @see get_sampling_rate()
  169. */
  170. var $samplingrate;
  171. /**
  172. * @var array
  173. * @see get_thumbnails()
  174. */
  175. var $thumbnails;
  176. /**
  177. * @var string
  178. * @see get_title()
  179. */
  180. var $title;
  181. /**
  182. * @var string
  183. * @see get_type()
  184. */
  185. var $type;
  186. /**
  187. * @var string
  188. * @see get_width()
  189. */
  190. var $width;
  191. /**
  192. * Constructor, used to input the data
  193. *
  194. * For documentation on all the parameters, see the corresponding
  195. * properties and their accessors
  196. *
  197. * @uses idna_convert If available, this will convert an IDN
  198. */
  199. 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)
  200. {
  201. $this->bitrate = $bitrate;
  202. $this->captions = $captions;
  203. $this->categories = $categories;
  204. $this->channels = $channels;
  205. $this->copyright = $copyright;
  206. $this->credits = $credits;
  207. $this->description = $description;
  208. $this->duration = $duration;
  209. $this->expression = $expression;
  210. $this->framerate = $framerate;
  211. $this->hashes = $hashes;
  212. $this->height = $height;
  213. $this->keywords = $keywords;
  214. $this->lang = $lang;
  215. $this->length = $length;
  216. $this->link = $link;
  217. $this->medium = $medium;
  218. $this->player = $player;
  219. $this->ratings = $ratings;
  220. $this->restrictions = $restrictions;
  221. $this->samplingrate = $samplingrate;
  222. $this->thumbnails = $thumbnails;
  223. $this->title = $title;
  224. $this->type = $type;
  225. $this->width = $width;
  226. if (class_exists('idna_convert'))
  227. {
  228. $idn = new idna_convert();
  229. $parsed = SimplePie_Misc::parse_url($link);
  230. $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  231. }
  232. $this->handler = $this->get_handler(); // Needs to load last
  233. }
  234. /**
  235. * String-ified version
  236. *
  237. * @return string
  238. */
  239. public function __toString()
  240. {
  241. // There is no $this->data here
  242. return md5(serialize($this));
  243. }
  244. /**
  245. * Get the bitrate
  246. *
  247. * @return string|null
  248. */
  249. public function get_bitrate()
  250. {
  251. if ($this->bitrate !== null)
  252. {
  253. return $this->bitrate;
  254. }
  255. else
  256. {
  257. return null;
  258. }
  259. }
  260. /**
  261. * Get a single caption
  262. *
  263. * @param int $key
  264. * @return SimplePie_Caption|null
  265. */
  266. public function get_caption($key = 0)
  267. {
  268. $captions = $this->get_captions();
  269. if (isset($captions[$key]))
  270. {
  271. return $captions[$key];
  272. }
  273. else
  274. {
  275. return null;
  276. }
  277. }
  278. /**
  279. * Get all captions
  280. *
  281. * @return array|null Array of {@see SimplePie_Caption} objects
  282. */
  283. public function get_captions()
  284. {
  285. if ($this->captions !== null)
  286. {
  287. return $this->captions;
  288. }
  289. else
  290. {
  291. return null;
  292. }
  293. }
  294. /**
  295. * Get a single category
  296. *
  297. * @param int $key
  298. * @return SimplePie_Category|null
  299. */
  300. public function get_category($key = 0)
  301. {
  302. $categories = $this->get_categories();
  303. if (isset($categories[$key]))
  304. {
  305. return $categories[$key];
  306. }
  307. else
  308. {
  309. return null;
  310. }
  311. }
  312. /**
  313. * Get all categories
  314. *
  315. * @return array|null Array of {@see SimplePie_Category} objects
  316. */
  317. public function get_categories()
  318. {
  319. if ($this->categories !== null)
  320. {
  321. return $this->categories;
  322. }
  323. else
  324. {
  325. return null;
  326. }
  327. }
  328. /**
  329. * Get the number of audio channels
  330. *
  331. * @return int|null
  332. */
  333. public function get_channels()
  334. {
  335. if ($this->channels !== null)
  336. {
  337. return $this->channels;
  338. }
  339. else
  340. {
  341. return null;
  342. }
  343. }
  344. /**
  345. * Get the copyright information
  346. *
  347. * @return SimplePie_Copyright|null
  348. */
  349. public function get_copyright()
  350. {
  351. if ($this->copyright !== null)
  352. {
  353. return $this->copyright;
  354. }
  355. else
  356. {
  357. return null;
  358. }
  359. }
  360. /**
  361. * Get a single credit
  362. *
  363. * @param int $key
  364. * @return SimplePie_Credit|null
  365. */
  366. public function get_credit($key = 0)
  367. {
  368. $credits = $this->get_credits();
  369. if (isset($credits[$key]))
  370. {
  371. return $credits[$key];
  372. }
  373. else
  374. {
  375. return null;
  376. }
  377. }
  378. /**
  379. * Get all credits
  380. *
  381. * @return array|null Array of {@see SimplePie_Credit} objects
  382. */
  383. public function get_credits()
  384. {
  385. if ($this->credits !== null)
  386. {
  387. return $this->credits;
  388. }
  389. else
  390. {
  391. return null;
  392. }
  393. }
  394. /**
  395. * Get the description of the enclosure
  396. *
  397. * @return string|null
  398. */
  399. public function get_description()
  400. {
  401. if ($this->description !== null)
  402. {
  403. return $this->description;
  404. }
  405. else
  406. {
  407. return null;
  408. }
  409. }
  410. /**
  411. * Get the duration of the enclosure
  412. *
  413. * @param string $convert Convert seconds into hh:mm:ss
  414. * @return string|int|null 'hh:mm:ss' string if `$convert` was specified, otherwise integer (or null if none found)
  415. */
  416. public function get_duration($convert = false)
  417. {
  418. if ($this->duration !== null)
  419. {
  420. if ($convert)
  421. {
  422. $time = SimplePie_Misc::time_hms($this->duration);
  423. return $time;
  424. }
  425. else
  426. {
  427. return $this->duration;
  428. }
  429. }
  430. else
  431. {
  432. return null;
  433. }
  434. }
  435. /**
  436. * Get the expression
  437. *
  438. * @return string Probably one of 'sample', 'full', 'nonstop', 'clip'. Defaults to 'full'
  439. */
  440. public function get_expression()
  441. {
  442. if ($this->expression !== null)
  443. {
  444. return $this->expression;
  445. }
  446. else
  447. {
  448. return 'full';
  449. }
  450. }
  451. /**
  452. * Get the file extension
  453. *
  454. * @return string|null
  455. */
  456. public function get_extension()
  457. {
  458. if ($this->link !== null)
  459. {
  460. $url = SimplePie_Misc::parse_url($this->link);
  461. if ($url['path'] !== '')
  462. {
  463. return pathinfo($url['path'], PATHINFO_EXTENSION);
  464. }
  465. }
  466. return null;
  467. }
  468. /**
  469. * Get the framerate (in frames-per-second)
  470. *
  471. * @return string|null
  472. */
  473. public function get_framerate()
  474. {
  475. if ($this->framerate !== null)
  476. {
  477. return $this->framerate;
  478. }
  479. else
  480. {
  481. return null;
  482. }
  483. }
  484. /**
  485. * Get the preferred handler
  486. *
  487. * @return string|null One of 'flash', 'fmedia', 'quicktime', 'wmedia', 'mp3'
  488. */
  489. public function get_handler()
  490. {
  491. return $this->get_real_type(true);
  492. }
  493. /**
  494. * Get a single hash
  495. *
  496. * @link http://www.rssboard.org/media-rss#media-hash
  497. * @param int $key
  498. * @return string|null Hash as per `media:hash`, prefixed with "$algo:"
  499. */
  500. public function get_hash($key = 0)
  501. {
  502. $hashes = $this->get_hashes();
  503. if (isset($hashes[$key]))
  504. {
  505. return $hashes[$key];
  506. }
  507. else
  508. {
  509. return null;
  510. }
  511. }
  512. /**
  513. * Get all credits
  514. *
  515. * @return array|null Array of strings, see {@see get_hash()}
  516. */
  517. public function get_hashes()
  518. {
  519. if ($this->hashes !== null)
  520. {
  521. return $this->hashes;
  522. }
  523. else
  524. {
  525. return null;
  526. }
  527. }
  528. /**
  529. * Get the height
  530. *
  531. * @return string|null
  532. */
  533. public function get_height()
  534. {
  535. if ($this->height !== null)
  536. {
  537. return $this->height;
  538. }
  539. else
  540. {
  541. return null;
  542. }
  543. }
  544. /**
  545. * Get the language
  546. *
  547. * @link http://tools.ietf.org/html/rfc3066
  548. * @return string|null Language code as per RFC 3066
  549. */
  550. public function get_language()
  551. {
  552. if ($this->lang !== null)
  553. {
  554. return $this->lang;
  555. }
  556. else
  557. {
  558. return null;
  559. }
  560. }
  561. /**
  562. * Get a single keyword
  563. *
  564. * @param int $key
  565. * @return string|null
  566. */
  567. public function get_keyword($key = 0)
  568. {
  569. $keywords = $this->get_keywords();
  570. if (isset($keywords[$key]))
  571. {
  572. return $keywords[$key];
  573. }
  574. else
  575. {
  576. return null;
  577. }
  578. }
  579. /**
  580. * Get all keywords
  581. *
  582. * @return array|null Array of strings
  583. */
  584. public function get_keywords()
  585. {
  586. if ($this->keywords !== null)
  587. {
  588. return $this->keywords;
  589. }
  590. else
  591. {
  592. return null;
  593. }
  594. }
  595. /**
  596. * Get length
  597. *
  598. * @return float Length in bytes
  599. */
  600. public function get_length()
  601. {
  602. if ($this->length !== null)
  603. {
  604. return $this->length;
  605. }
  606. else
  607. {
  608. return null;
  609. }
  610. }
  611. /**
  612. * Get the URL
  613. *
  614. * @return string|null
  615. */
  616. public function get_link()
  617. {
  618. if ($this->link !== null)
  619. {
  620. return urldecode($this->link);
  621. }
  622. else
  623. {
  624. return null;
  625. }
  626. }
  627. /**
  628. * Get the medium
  629. *
  630. * @link http://www.rssboard.org/media-rss#media-content
  631. * @return string|null Should be one of 'image', 'audio', 'video', 'document', 'executable'
  632. */
  633. public function get_medium()
  634. {
  635. if ($this->medium !== null)
  636. {
  637. return $this->medium;
  638. }
  639. else
  640. {
  641. return null;
  642. }
  643. }
  644. /**
  645. * Get the player URL
  646. *
  647. * Typically the same as {@see get_permalink()}
  648. * @return string|null Player URL
  649. */
  650. public function get_player()
  651. {
  652. if ($this->player !== null)
  653. {
  654. return $this->player;
  655. }
  656. else
  657. {
  658. return null;
  659. }
  660. }
  661. /**
  662. * Get a single rating
  663. *
  664. * @param int $key
  665. * @return SimplePie_Rating|null
  666. */
  667. public function get_rating($key = 0)
  668. {
  669. $ratings = $this->get_ratings();
  670. if (isset($ratings[$key]))
  671. {
  672. return $ratings[$key];
  673. }
  674. else
  675. {
  676. return null;
  677. }
  678. }
  679. /**
  680. * Get all ratings
  681. *
  682. * @return array|null Array of {@see SimplePie_Rating} objects
  683. */
  684. public function get_ratings()
  685. {
  686. if ($this->ratings !== null)
  687. {
  688. return $this->ratings;
  689. }
  690. else
  691. {
  692. return null;
  693. }
  694. }
  695. /**
  696. * Get a single restriction
  697. *
  698. * @param int $key
  699. * @return SimplePie_Restriction|null
  700. */
  701. public function get_restriction($key = 0)
  702. {
  703. $restrictions = $this->get_restrictions();
  704. if (isset($restrictions[$key]))
  705. {
  706. return $restrictions[$key];
  707. }
  708. else
  709. {
  710. return null;
  711. }
  712. }
  713. /**
  714. * Get all restrictions
  715. *
  716. * @return array|null Array of {@see SimplePie_Restriction} objects
  717. */
  718. public function get_restrictions()
  719. {
  720. if ($this->restrictions !== null)
  721. {
  722. return $this->restrictions;
  723. }
  724. else
  725. {
  726. return null;
  727. }
  728. }
  729. /**
  730. * Get the sampling rate (in kHz)
  731. *
  732. * @return string|null
  733. */
  734. public function get_sampling_rate()
  735. {
  736. if ($this->samplingrate !== null)
  737. {
  738. return $this->samplingrate;
  739. }
  740. else
  741. {
  742. return null;
  743. }
  744. }
  745. /**
  746. * Get the file size (in MiB)
  747. *
  748. * @return float|null File size in mebibytes (1048 bytes)
  749. */
  750. public function get_size()
  751. {
  752. $length = $this->get_length();
  753. if ($length !== null)
  754. {
  755. return round($length/1048576, 2);
  756. }
  757. else
  758. {
  759. return null;
  760. }
  761. }
  762. /**
  763. * Get a single thumbnail
  764. *
  765. * @param int $key
  766. * @return string|null Thumbnail URL
  767. */
  768. public function get_thumbnail($key = 0)
  769. {
  770. $thumbnails = $this->get_thumbnails();
  771. if (isset($thumbnails[$key]))
  772. {
  773. return $thumbnails[$key];
  774. }
  775. else
  776. {
  777. return null;
  778. }
  779. }
  780. /**
  781. * Get all thumbnails
  782. *
  783. * @return array|null Array of thumbnail URLs
  784. */
  785. public function get_thumbnails()
  786. {
  787. if ($this->thumbnails !== null)
  788. {
  789. return $this->thumbnails;
  790. }
  791. else
  792. {
  793. return null;
  794. }
  795. }
  796. /**
  797. * Get the title
  798. *
  799. * @return string|null
  800. */
  801. public function get_title()
  802. {
  803. if ($this->title !== null)
  804. {
  805. return $this->title;
  806. }
  807. else
  808. {
  809. return null;
  810. }
  811. }
  812. /**
  813. * Get mimetype of the enclosure
  814. *
  815. * @see get_real_type()
  816. * @return string|null MIME type
  817. */
  818. public function get_type()
  819. {
  820. if ($this->type !== null)
  821. {
  822. return $this->type;
  823. }
  824. else
  825. {
  826. return null;
  827. }
  828. }
  829. /**
  830. * Get the width
  831. *
  832. * @return string|null
  833. */
  834. public function get_width()
  835. {
  836. if ($this->width !== null)
  837. {
  838. return $this->width;
  839. }
  840. else
  841. {
  842. return null;
  843. }
  844. }
  845. /**
  846. * Embed the enclosure using `<embed>`
  847. *
  848. * @deprecated Use the second parameter to {@see embed} instead
  849. *
  850. * @param array|string $options See first paramter to {@see embed}
  851. * @return string HTML string to output
  852. */
  853. public function native_embed($options='')
  854. {
  855. return $this->embed($options, true);
  856. }
  857. /**
  858. * Embed the enclosure using Javascript
  859. *
  860. * `$options` is an array or comma-separated key:value string, with the
  861. * following properties:
  862. *
  863. * - `alt` (string): Alternate content for when an end-user does not have
  864. * the appropriate handler installed or when a file type is
  865. * unsupported. Can be any text or HTML. Defaults to blank.
  866. * - `altclass` (string): If a file type is unsupported, the end-user will
  867. * see the alt text (above) linked directly to the content. That link
  868. * will have this value as its class name. Defaults to blank.
  869. * - `audio` (string): This is an image that should be used as a
  870. * placeholder for audio files before they're loaded (QuickTime-only).
  871. * Can be any relative or absolute URL. Defaults to blank.
  872. * - `bgcolor` (string): The background color for the media, if not
  873. * already transparent. Defaults to `#ffffff`.
  874. * - `height` (integer): The height of the embedded media. Accepts any
  875. * numeric pixel value (such as `360`) or `auto`. Defaults to `auto`,
  876. * and it is recommended that you use this default.
  877. * - `loop` (boolean): Do you want the media to loop when its done?
  878. * Defaults to `false`.
  879. * - `mediaplayer` (string): The location of the included
  880. * `mediaplayer.swf` file. This allows for the playback of Flash Video
  881. * (`.flv`) files, and is the default handler for non-Odeo MP3's.
  882. * Defaults to blank.
  883. * - `video` (string): This is an image that should be used as a
  884. * placeholder for video files before they're loaded (QuickTime-only).
  885. * Can be any relative or absolute URL. Defaults to blank.
  886. * - `width` (integer): The width of the embedded media. Accepts any
  887. * numeric pixel value (such as `480`) or `auto`. Defaults to `auto`,
  888. * and it is recommended that you use this default.
  889. * - `widescreen` (boolean): Is the enclosure widescreen or standard?
  890. * This applies only to video enclosures, and will automatically resize
  891. * the content appropriately. Defaults to `false`, implying 4:3 mode.
  892. *
  893. * Note: Non-widescreen (4:3) mode with `width` and `height` set to `auto`
  894. * will default to 480x360 video resolution. Widescreen (16:9) mode with
  895. * `width` and `height` set to `auto` will default to 480x270 video resolution.
  896. *
  897. * @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'.
  898. * @param array|string $options Comma-separated key:value list, or array
  899. * @param bool $native Use `<embed>`
  900. * @return string HTML string to output
  901. */
  902. public function embed($options = '', $native = false)
  903. {
  904. // Set up defaults
  905. $audio = '';
  906. $video = '';
  907. $alt = '';
  908. $altclass = '';
  909. $loop = 'false';
  910. $width = 'auto';
  911. $height = 'auto';
  912. $bgcolor = '#ffffff';
  913. $mediaplayer = '';
  914. $widescreen = false;
  915. $handler = $this->get_handler();
  916. $type = $this->get_real_type();
  917. // Process options and reassign values as necessary
  918. if (is_array($options))
  919. {
  920. extract($options);
  921. }
  922. else
  923. {
  924. $options = explode(',', $options);
  925. foreach($options as $option)
  926. {
  927. $opt = explode(':', $option, 2);
  928. if (isset($opt[0], $opt[1]))
  929. {
  930. $opt[0] = trim($opt[0]);
  931. $opt[1] = trim($opt[1]);
  932. switch ($opt[0])
  933. {
  934. case 'audio':
  935. $audio = $opt[1];
  936. break;
  937. case 'video':
  938. $video = $opt[1];
  939. break;
  940. case 'alt':
  941. $alt = $opt[1];
  942. break;
  943. case 'altclass':
  944. $altclass = $opt[1];
  945. break;
  946. case 'loop':
  947. $loop = $opt[1];
  948. break;
  949. case 'width':
  950. $width = $opt[1];
  951. break;
  952. case 'height':
  953. $height = $opt[1];
  954. break;
  955. case 'bgcolor':
  956. $bgcolor = $opt[1];
  957. break;
  958. case 'mediaplayer':
  959. $mediaplayer = $opt[1];
  960. break;
  961. case 'widescreen':
  962. $widescreen = $opt[1];
  963. break;
  964. }
  965. }
  966. }
  967. }
  968. $mime = explode('/', $type, 2);
  969. $mime = $mime[0];
  970. // Process values for 'auto'
  971. if ($width === 'auto')
  972. {
  973. if ($mime === 'video')
  974. {
  975. if ($height === 'auto')
  976. {
  977. $width = 480;
  978. }
  979. elseif ($widescreen)
  980. {
  981. $width = round((intval($height)/9)*16);
  982. }
  983. else
  984. {
  985. $width = round((intval($height)/3)*4);
  986. }
  987. }
  988. else
  989. {
  990. $width = '100%';
  991. }
  992. }
  993. if ($height === 'auto')
  994. {
  995. if ($mime === 'audio')
  996. {
  997. $height = 0;
  998. }
  999. elseif ($mime === 'video')
  1000. {
  1001. if ($width === 'auto')
  1002. {
  1003. if ($widescreen)
  1004. {
  1005. $height = 270;
  1006. }
  1007. else
  1008. {
  1009. $height = 360;
  1010. }
  1011. }
  1012. elseif ($widescreen)
  1013. {
  1014. $height = round((intval($width)/16)*9);
  1015. }
  1016. else
  1017. {
  1018. $height = round((intval($width)/4)*3);
  1019. }
  1020. }
  1021. else
  1022. {
  1023. $height = 376;
  1024. }
  1025. }
  1026. elseif ($mime === 'audio')
  1027. {
  1028. $height = 0;
  1029. }
  1030. // Set proper placeholder value
  1031. if ($mime === 'audio')
  1032. {
  1033. $placeholder = $audio;
  1034. }
  1035. elseif ($mime === 'video')
  1036. {
  1037. $placeholder = $video;
  1038. }
  1039. $embed = '';
  1040. // Flash
  1041. if ($handler === 'flash')
  1042. {
  1043. if ($native)
  1044. {
  1045. $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>";
  1046. }
  1047. else
  1048. {
  1049. $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
  1050. }
  1051. }
  1052. // Flash Media Player file types.
  1053. // Preferred handler for MP3 file types.
  1054. elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== ''))
  1055. {
  1056. $height += 20;
  1057. if ($native)
  1058. {
  1059. $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>";
  1060. }
  1061. else
  1062. {
  1063. $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
  1064. }
  1065. }
  1066. // QuickTime 7 file types. Need to test with QuickTime 6.
  1067. // Only handle MP3's if the Flash Media Player is not present.
  1068. elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === ''))
  1069. {
  1070. $height += 16;
  1071. if ($native)
  1072. {
  1073. if ($placeholder !== '')
  1074. {
  1075. $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>";
  1076. }
  1077. else
  1078. {
  1079. $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>";
  1080. }
  1081. }
  1082. else
  1083. {
  1084. $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
  1085. }
  1086. }
  1087. // Windows Media
  1088. elseif ($handler === 'wmedia')
  1089. {
  1090. $height += 45;
  1091. if ($native)
  1092. {
  1093. $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>";
  1094. }
  1095. else
  1096. {
  1097. $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
  1098. }
  1099. }
  1100. // Everything else
  1101. else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
  1102. return $embed;
  1103. }
  1104. /**
  1105. * Get the real media type
  1106. *
  1107. * Often, feeds lie to us, necessitating a bit of deeper inspection. This
  1108. * converts types to their canonical representations based on the file
  1109. * extension
  1110. *
  1111. * @see get_type()
  1112. * @param bool $find_handler Internal use only, use {@see get_handler()} instead
  1113. * @return string MIME type
  1114. */
  1115. public function get_real_type($find_handler = false)
  1116. {
  1117. // Mime-types by handler.
  1118. $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
  1119. $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player
  1120. $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
  1121. $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
  1122. $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3
  1123. if ($this->get_type() !== null)
  1124. {
  1125. $type = strtolower($this->type);
  1126. }
  1127. else
  1128. {
  1129. $type = null;
  1130. }
  1131. // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
  1132. if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
  1133. {
  1134. switch (strtolower($this->get_extension()))
  1135. {
  1136. // Audio mime-types
  1137. case 'aac':
  1138. case 'adts':
  1139. $type = 'audio/acc';
  1140. break;
  1141. case 'aif':
  1142. case 'aifc':
  1143. case 'aiff':
  1144. case 'cdda':
  1145. $type = 'audio/aiff';
  1146. break;
  1147. case 'bwf':
  1148. $type = 'audio/wav';
  1149. break;
  1150. case 'kar':
  1151. case 'mid':
  1152. case 'midi':
  1153. case 'smf':
  1154. $type = 'audio/midi';
  1155. break;
  1156. case 'm4a':
  1157. $type = 'audio/x-m4a';
  1158. break;
  1159. case 'mp3':
  1160. case 'swa':
  1161. $type = 'audio/mp3';
  1162. break;
  1163. case 'wav':
  1164. $type = 'audio/wav';
  1165. break;
  1166. case 'wax':
  1167. $type = 'audio/x-ms-wax';
  1168. break;
  1169. case 'wma':
  1170. $type = 'audio/x-ms-wma';
  1171. break;
  1172. // Video mime-types
  1173. case '3gp':
  1174. case '3gpp':
  1175. $type = 'video/3gpp';
  1176. break;
  1177. case '3g2':
  1178. case '3gp2':
  1179. $type = 'video/3gpp2';
  1180. break;
  1181. case 'asf':
  1182. $type = 'video/x-ms-asf';
  1183. break;
  1184. case 'flv':
  1185. $type = 'video/x-flv';
  1186. break;
  1187. case 'm1a':
  1188. case 'm1s':
  1189. case 'm1v':
  1190. case 'm15':
  1191. case 'm75':
  1192. case 'mp2':
  1193. case 'mpa':
  1194. case 'mpeg':
  1195. case 'mpg':
  1196. case 'mpm':
  1197. case 'mpv':
  1198. $type = 'video/mpeg';
  1199. break;
  1200. case 'm4v':
  1201. $type = 'video/x-m4v';
  1202. break;
  1203. case 'mov':
  1204. case 'qt':
  1205. $type = 'video/quicktime';
  1206. break;
  1207. case 'mp4':
  1208. case 'mpg4':
  1209. $type = 'video/mp4';
  1210. break;
  1211. case 'sdv':
  1212. $type = 'video/sd-video';
  1213. break;
  1214. case 'wm':
  1215. $type = 'video/x-ms-wm';
  1216. break;
  1217. case 'wmv':
  1218. $type = 'video/x-ms-wmv';
  1219. break;
  1220. case 'wvx':
  1221. $type = 'video/x-ms-wvx';
  1222. break;
  1223. // Flash mime-types
  1224. case 'spl':
  1225. $type = 'application/futuresplash';
  1226. break;
  1227. case 'swf':
  1228. $type = 'application/x-shockwave-flash';
  1229. break;
  1230. }
  1231. }
  1232. if ($find_handler)
  1233. {
  1234. if (in_array($type, $types_flash))
  1235. {
  1236. return 'flash';
  1237. }
  1238. elseif (in_array($type, $types_fmedia))
  1239. {
  1240. return 'fmedia';
  1241. }
  1242. elseif (in_array($type, $types_quicktime))
  1243. {
  1244. return 'quicktime';
  1245. }
  1246. elseif (in_array($type, $types_wmedia))
  1247. {
  1248. return 'wmedia';
  1249. }
  1250. elseif (in_array($type, $types_mp3))
  1251. {
  1252. return 'mp3';
  1253. }
  1254. else
  1255. {
  1256. return null;
  1257. }
  1258. }
  1259. else
  1260. {
  1261. return $type;
  1262. }
  1263. }
  1264. }