/src/Zend/Media/Id3/Frame/Wxxx.php

http://php-reader.googlecode.com/ · PHP · 180 lines · 74 code · 12 blank · 94 comment · 4 complexity · 1e97ce2fc567af89e9463f5d581bd7cb MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Media
  17. * @subpackage ID3
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Wxxx.php 177 2010-03-09 13:13:34Z svollbehr $
  21. */
  22. /**#@+ @ignore */
  23. require_once 'Zend/Media/Id3/LinkFrame.php';
  24. require_once 'Zend/Media/Id3/Encoding.php';
  25. /**#@-*/
  26. /**
  27. * This frame is intended for URL links concerning the audio file in a similar
  28. * way to the other 'W'-frames. The frame body consists of a description of the
  29. * string followed by the actual URL. The URL is always encoded with ISO-8859-1.
  30. * There may be more than one 'WXXX' frame in each tag, but only one with the
  31. * same description.
  32. *
  33. * @category Zend
  34. * @package Zend_Media
  35. * @subpackage ID3
  36. * @author Sven Vollbehr <sven@vollbehr.eu>
  37. * @author Ryan Butterfield <buttza@gmail.com>
  38. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @version $Id: Wxxx.php 177 2010-03-09 13:13:34Z svollbehr $
  41. */
  42. final class Zend_Media_Id3_Frame_Wxxx extends Zend_Media_Id3_LinkFrame
  43. implements Zend_Media_Id3_Encoding
  44. {
  45. /** @var integer */
  46. private $_encoding;
  47. /** @var string */
  48. private $_description;
  49. /**
  50. * Constructs the class with given parameters and parses object related
  51. * data.
  52. *
  53. * @param Zend_Io_Reader $reader The reader object.
  54. * @param Array $options The options array.
  55. */
  56. public function __construct($reader = null, &$options = array())
  57. {
  58. Zend_Media_Id3_Frame::__construct($reader, $options);
  59. $this->setEncoding
  60. ($this->getOption('encoding', Zend_Media_Id3_Encoding::UTF8));
  61. if ($this->_reader === null) {
  62. return;
  63. }
  64. $encoding = $this->_reader->readUInt8();
  65. switch ($encoding) {
  66. case self::UTF16:
  67. // break intentionally omitted
  68. case self::UTF16BE:
  69. list($this->_description, $this->_link) =
  70. $this->_explodeString16
  71. ($this->_reader->read($this->_reader->getSize()), 2);
  72. break;
  73. case self::UTF8:
  74. // break intentionally omitted
  75. default:
  76. list($this->_description, $this->_link) =
  77. $this->_explodeString8
  78. ($this->_reader->read($this->_reader->getSize()), 2);
  79. break;
  80. }
  81. $this->_description =
  82. $this->_convertString($this->_description, $encoding);
  83. $this->_link = implode($this->_explodeString8($this->_link, 1), '');
  84. }
  85. /**
  86. * Returns the text encoding.
  87. *
  88. * All the strings read from a file are automatically converted to the
  89. * character encoding specified with the <var>encoding</var> option. See
  90. * {@link Zend_Media_Id3v2} for details. This method returns that character
  91. * encoding, or any value set after read, translated into a string form
  92. * regarless if it was set using a {@link Zend_Media_Id3_Encoding} constant
  93. * or a string.
  94. *
  95. * @return integer
  96. */
  97. public function getEncoding()
  98. {
  99. return $this->_translateIntToEncoding($this->_encoding);
  100. }
  101. /**
  102. * Sets the text encoding.
  103. *
  104. * All the string written to the frame are done so using given character
  105. * encoding. No conversions of existing data take place upon the call to
  106. * this method thus all texts must be given in given character encoding.
  107. *
  108. * The character encoding parameter takes either a
  109. * {@link Zend_Media_Id3_Encoding} constant or a character set name string
  110. * in the form accepted by iconv. The default character encoding used to
  111. * write the frame is 'utf-8'.
  112. *
  113. * @see Zend_Media_Id3_Encoding
  114. * @param integer $encoding The text encoding.
  115. */
  116. public function setEncoding($encoding)
  117. {
  118. $this->_encoding = $this->_translateEncodingToInt($encoding);
  119. }
  120. /**
  121. * Returns the link description.
  122. *
  123. * @return string
  124. */
  125. public function getDescription()
  126. {
  127. return $this->_description;
  128. }
  129. /**
  130. * Sets the content description text using given encoding.
  131. *
  132. * @param string $description The content description text.
  133. * @param integer $encoding The text encoding.
  134. */
  135. public function setDescription($description, $encoding = null)
  136. {
  137. $this->_description = $description;
  138. if ($encoding !== null) {
  139. $this->setEncoding($encoding);
  140. }
  141. }
  142. /**
  143. * Writes the frame raw data without the header.
  144. *
  145. * @param Zend_Io_Writer $writer The writer object.
  146. * @return void
  147. */
  148. protected function _writeData($writer)
  149. {
  150. $writer->writeUInt8($this->_encoding);
  151. switch ($this->_encoding) {
  152. case self::UTF16LE:
  153. $writer->writeString16
  154. ($this->_description,
  155. Zend_Io_Writer::LITTLE_ENDIAN_ORDER, 1);
  156. break;
  157. case self::UTF16:
  158. // break intentionally omitted
  159. case self::UTF16BE:
  160. $writer->writeString16($this->_description, null, 1);
  161. break;
  162. default:
  163. $writer->writeString8($this->_description, 1);
  164. break;
  165. }
  166. $writer->write($this->_link);
  167. }
  168. }