Fix bugs and apply new code as described in issue 11
git-svn-id: http://php-reader.googlecode.com/svn/trunk@105 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
@@ -53,6 +53,7 @@ require_once("ID3/Exception.php");
|
||||
* @package php-reader
|
||||
* @subpackage ID3
|
||||
* @author Sven Vollbehr <svollbehr@gmail.com>
|
||||
* @author Ryan Butterfield <buttza@gmail.com>
|
||||
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
|
||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||
* @version $Rev$
|
||||
@@ -64,7 +65,7 @@ final class ID3_Frame_COMM extends ID3_Frame
|
||||
private $_encoding = ID3_Encoding::UTF8;
|
||||
|
||||
/** @var string */
|
||||
private $_language = "eng";
|
||||
private $_language = "und";
|
||||
|
||||
/** @var string */
|
||||
private $_description;
|
||||
@@ -85,26 +86,28 @@ final class ID3_Frame_COMM extends ID3_Frame
|
||||
if ($reader === null)
|
||||
return;
|
||||
|
||||
$this->_encoding = Transform::fromInt8($this->_data[0]);
|
||||
$this->_encoding = Transform::fromUInt8($this->_data[0]);
|
||||
$this->_language = substr($this->_data, 1, 3);
|
||||
if ($this->_language == "XXX")
|
||||
$this->_language = "und";
|
||||
$this->_data = substr($this->_data, 4);
|
||||
|
||||
switch ($this->_encoding) {
|
||||
case self::UTF16:
|
||||
list ($this->_description, $this->_text) =
|
||||
preg_split("/\\x00\\x00/", $this->_data, 2);
|
||||
$this->explodeString16($this->_data, 2);
|
||||
$this->_description = Transform::fromString16($this->_description);
|
||||
$this->_text = Transform::fromString16($this->_text);
|
||||
break;
|
||||
case self::UTF16BE:
|
||||
list ($this->_description, $this->_text) =
|
||||
preg_split("/\\x00\\x00/", $this->_data, 2);
|
||||
$this->explodeString16($this->_data, 2);
|
||||
$this->_description = Transform::fromString16BE($this->_description);
|
||||
$this->_text = Transform::fromString16BE($this->_text);
|
||||
break;
|
||||
default:
|
||||
list ($this->_description, $this->_text) =
|
||||
preg_split("/\\x00/", $this->_data, 2);
|
||||
$this->explodeString8($this->_data, 2);
|
||||
$this->_description = Transform::fromString8($this->_description);
|
||||
$this->_text = Transform::fromString8($this->_text);
|
||||
}
|
||||
@@ -140,7 +143,12 @@ final class ID3_Frame_COMM extends ID3_Frame
|
||||
* @see ID3_Language
|
||||
* @param string $language The language code.
|
||||
*/
|
||||
public function setLanguage($language) { $this->_language = $language; }
|
||||
public function setLanguage($language)
|
||||
{
|
||||
if ($language == "XXX")
|
||||
$language = "und";
|
||||
$this->_language = substr($language, 0, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the short content description.
|
||||
@@ -162,9 +170,9 @@ final class ID3_Frame_COMM extends ID3_Frame
|
||||
{
|
||||
$this->_description = $description;
|
||||
if ($language !== false)
|
||||
$this->_language = $language;
|
||||
$this->setLanguage($language);
|
||||
if ($encoding !== false)
|
||||
$this->_encoding = $encoding;
|
||||
$this->setEncoding($encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,9 +194,9 @@ final class ID3_Frame_COMM extends ID3_Frame
|
||||
{
|
||||
$this->_text = $text;
|
||||
if ($language !== false)
|
||||
$this->_language = $language;
|
||||
$this->setLanguage($language);
|
||||
if ($encoding !== false)
|
||||
$this->_encoding = $encoding;
|
||||
$this->setEncoding($encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,19 +206,18 @@ final class ID3_Frame_COMM extends ID3_Frame
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$data = Transform::toInt8($this->_encoding) . $this->_language;
|
||||
$data = Transform::toUInt8($this->_encoding) . $this->_language;
|
||||
switch ($this->_encoding) {
|
||||
case self::UTF16:
|
||||
$data .= Transform::toString16($this->_description) . "\0\0" .
|
||||
Transform::toString16($this->_text);
|
||||
case self::UTF16LE:
|
||||
$order = $this->_encoding == self::UTF16 ?
|
||||
Transform::MACHINE_ENDIAN_ORDER : Transform::LITTLE_ENDIAN_ORDER;
|
||||
$data .= Transform::toString16($this->_description, $order) . "\0\0" .
|
||||
Transform::toString16($this->_text, $order);
|
||||
break;
|
||||
case self::UTF16BE:
|
||||
$data .= Transform::toString16BE($this->_description) . "\0\0" .
|
||||
Transform::toString16BE($this->_text);
|
||||
break;
|
||||
case self::UTF16LE:
|
||||
$data .= Transform::toString16LE($this->_description) . "\0\0" .
|
||||
Transform::toString16LE($this->_text);
|
||||
$data .= Transform::toString16BE
|
||||
($this->_description . "\0\0" . $this->_text);
|
||||
break;
|
||||
default:
|
||||
$data .= $this->_description . "\0" . $this->_text;
|
||||
|
||||
Reference in New Issue
Block a user