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:
svollbehr
2008-07-30 14:56:47 +00:00
parent c747c406d8
commit 809bf58885
34 changed files with 1002 additions and 555 deletions

View File

@@ -49,6 +49,7 @@ require_once("ID3/Encoding.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$
@@ -59,10 +60,10 @@ final class ID3_Frame_IPLS extends ID3_Frame
{
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
/** @var Array */
private $_people = array();
/**
* Constructs the class with given parameters and parses object related data.
*
@@ -72,71 +73,75 @@ final class ID3_Frame_IPLS extends ID3_Frame
public function __construct($reader = null, &$options = array())
{
parent::__construct($reader, $options);
if ($reader === null)
return;
$this->_encoding = Transform::fromInt8($this->_data[0]);
$data = array();
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$data = substr($this->_data, 1);
$order = Transform::MACHINE_ENDIAN_ORDER;
switch ($this->_encoding) {
case self::UTF16:
$data = preg_split
("/\\x00\\x00/", Transform::fromString16($this->_data));
$data = $this->explodeString16($data);
foreach ($data as &$str)
$str = Transform::fromString16($str, $order);
break;
case self::UTF16BE:
$data = preg_split
("/\\x00\\x00/", Transform::fromString16BE($this->_data));
$data = $this->explodeString16($data);
foreach ($data as &$str)
$str = Transform::fromString16BE($str);
break;
default:
$data = preg_split("/\\x00/", $this->_data);
$data = $this->explodeString8($data);
}
for ($i = 0; $i < count($data); $i+=2)
for ($i = 0; $i < count($data) - 1; $i += 2)
$this->_people[] = array($data[$i] => @$data[$i + 1]);
}
/**
* Returns the text encoding.
*
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
/**
* Sets the text encoding.
*
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/
public function setEncoding($encoding) { $this->_encoding = $encoding; }
/**
* Returns the involved people list as an array. For each person, the array
* contains an entry, which too is an associate array with involvement as its
* key and involvee as its value.
*
*
* @return Array
*/
public function getPeople() { return $this->_people; }
/**
* Adds a person with his involvement.
*
*
* @return string
*/
public function addPerson($involvement, $person)
{
$this->_people[] = array($involvement => $person);
}
/**
* Sets the involved people list array. For each person, the array must
* contain an associate array with involvement as its key and involvee as its
* value.
*
*
* @param Array $people The involved people list.
*/
public function setPeople($people) { $this->_people = $people; }
/**
* Returns the frame raw data.
*
@@ -144,19 +149,20 @@ final class ID3_Frame_IPLS extends ID3_Frame
*/
public function __toString()
{
$data = Transform::toInt8($this->_encoding);
$data = Transform::toUInt8($this->_encoding);
$order = $this->_encoding == self::UTF16 ?
Transform::MACHINE_ENDIAN_ORDER : Transform::LITTLE_ENDIAN_ORDER;
foreach ($this->_people as $entry) {
foreach ($entry as $key => $val) {
switch ($this->_encoding) {
case self::UTF16:
$data .= Transform::toString16($key . "\0\0" . $val . "\0\0");
case self::UTF16LE:
$data .= Transform::toString16($key, $order) . "\0\0" .
Transform::toString16($val, $order) . "\0\0";
break;
case self::UTF16BE:
$data .= Transform::toString16BE($key . "\0\0" . $val . "\0\0");
break;
case self::UTF16LE:
$data .= Transform::toString16LE($key . "\0\0" . $val . "\0\0");
break;
default:
$data .= $key . "\0" . $val . "\0";
}