PageRenderTime 35ms CodeModel.GetById 23ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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