Exemple #1
0
 /**
  * Constructs the Id3v1 class with given file. The file is not mandatory
  * argument and may be omitted as a new tag can be written to a file also by
  * giving the filename to the {@link #write} method of this class.
  *
  * @param string|resource|Zend_Io_Reader $filename The path to the file,
  *  file descriptor of an opened file, or a {@link Zend_Io_Reader} instance.
  * @throws Zend_Media_Id3_Exception if given file descriptor is not valid
  */
 public function __construct($filename = null)
 {
     if ($filename === null) {
         return;
     }
     if ($filename instanceof Zend_Io_Reader) {
         $this->_reader =& $filename;
     } else {
         $this->_filename = $filename;
         require_once 'Zend/Io/FileReader.php';
         try {
             $this->_reader = new Zend_Io_FileReader($filename);
         } catch (Zend_Io_Exception $e) {
             $this->_reader = null;
             require_once 'Zend/Media/Id3/Exception.php';
             throw new Zend_Media_Id3_Exception($e->getMessage());
         }
     }
     if ($this->_reader->getSize() < 128) {
         $this->_reader = null;
         require_once 'Zend/Media/Id3/Exception.php';
         throw new Zend_Media_Id3_Exception('File does not contain ID3v1 tag');
     }
     $this->_reader->setOffset(-128);
     if ($this->_reader->read(3) != 'TAG') {
         $this->_reader = null;
         require_once 'Zend/Media/Id3/Exception.php';
         throw new Zend_Media_Id3_Exception('File does not contain ID3v1 tag');
     }
     $this->_title = $this->_reader->readString8(30, " ");
     $this->_artist = $this->_reader->readString8(30, " ");
     $this->_album = $this->_reader->readString8(30, " ");
     $this->_year = $this->_reader->readString8(4);
     $this->_comment = $this->_reader->readString8(28);
     /* ID3v1.1 support for tracks */
     $v11_null = $this->_reader->read(1);
     $v11_track = $this->_reader->read(1);
     if (ord($v11_null) == 0 && ord($v11_track) != 0) {
         $this->_track = ord($v11_track);
     } else {
         $this->_comment = rtrim($this->_comment . $v11_null . $v11_track, " ");
     }
     $this->_genre = $this->_reader->readInt8();
 }
Exemple #2
0
 /**
  * Reads 1 record from the file.
  */
 protected function readRecord()
 {
     $record_header = $this->readRecordHeader();
     $local_msg_type = $record_header['Local Message Type'];
     if ($record_header['Message Type'] === true) {
         //this is a definition message
         $def = $this->readRecordDefinition();
         $this->message_type_definitions[$local_msg_type] = $def;
     } else {
         $def = $this->message_type_definitions[$local_msg_type];
         $data = array();
         /*
          * Architecture Type
          * 0: Definition and Data Messages are Little Endian
          * 1: Definition and Data Message are Big Endian
          */
         $big_endian = $def['architecture'] === 1;
         if ($this->file_type === null) {
             //default filetype, file_id is overal hetzelfde
             $this->file_type = \Fit\FileType::activity;
         }
         foreach ($def['fields'] as $field_def) {
             $profile_field_def = $this->profile->findFieldDefinition($this->file_type, $def['global_msg_number'], $field_def['field_def_number']);
             if ($profile_field_def) {
                 $field_name = $profile_field_def[\Fit\Field::NAME];
                 $field_factor = (double) $profile_field_def[\Fit\Field::FACTOR];
                 $field_unit = $profile_field_def[\Fit\Field::UNIT];
             } else {
                 $field_name = 'no:' . $field_def['field_def_number'];
                 $field_factor = 1;
                 $field_unit = '';
             }
             switch ($field_def['base_type']['base_type_definition']['name']) {
                 case 'string':
                     $value = $this->reader->readString8($field_def['size']);
                     break;
                 case 'sint8':
                     $value = $this->reader->readInt8();
                     break;
                 case 'enum':
                 case 'uint8z':
                 case 'uint8':
                     $value = $this->reader->readUInt8();
                     break;
                 case 'sint16':
                     $value = $big_endian ? $this->reader->readInt16BE() : $this->reader->readInt16LE();
                     break;
                 case 'uint16z':
                 case 'uint16':
                     $value = $big_endian ? $this->reader->readUInt16BE() : $this->reader->readUInt16LE();
                     break;
                 case 'sint32':
                     $value = $big_endian ? $this->reader->readInt32BE() : $this->reader->readInt32LE();
                     break;
                 case 'uint32z':
                 case 'uint32':
                     $value = $big_endian ? $this->reader->readUInt32BE() : $this->reader->readUInt32LE();
                     break;
                 case 'float32':
                     $value = $big_endian ? $this->reader->readFloatBE() : $this->reader->readFloatLE();
                     break;
                 case 'float64':
                     $value = $big_endian ? $this->reader->readDoubleBE() : $this->reader->readDoubleLE();
                     break;
                 case 'byte':
                 default:
                     $value = $this->reader->read($field_def['size']);
             }
             if (is_numeric($value) && $field_factor > 0) {
                 $value *= $field_factor;
             }
             $data[$field_name] = array('value' => $value, 'unit' => $field_unit);
             if ($def['global_msg_number'] === 0 && $field_name === 'type') {
                 $this->file_type = $value;
             }
         }
         $this->records[] = $data;
     }
 }
Exemple #3
0
    /**
     * Reads 1 record from the file.
     */
    protected function readRecord()
    {
        $record_header = $this->readRecordHeader();
        $local_msg_type = $record_header['Local Message Type'];
        if ($record_header['Message Type'] === true) {
            //this is a definition message
            $def = $this->readRecordDefinition();
            $this->message_type_definitions[$local_msg_type] = $def;
        } else {
            //this is a data message
            $def = $this->message_type_definitions[$local_msg_type];
            $data = array();
            /*
             * Architecture Type 
             * 0: Definition and Data Messages are Little Endian 
             * 1: Definition and Data Message are Big Endian
             */
            $big_endian = $def['architecture'] === 1;
            if ($this->file_type === null) {
                //default filetype, file_id is overal hetzelfde
                $this->file_type = \Fit\FileType::activity;
            }
            foreach ($def['fields'] as $field_def) {
                $profile_field_def = $this->profile->findFieldDefinition($this->file_type, $def['global_msg_number'], $field_def['field_def_number']);
                if ($profile_field_def) {
                    $field_name = $profile_field_def[\Fit\Field::NAME];
                    $field_factor = (double) $profile_field_def[\Fit\Field::FACTOR];
                    $field_unit = $profile_field_def[\Fit\Field::UNIT];
                } else {
                    $field_name = 'no:' . $field_def['field_def_number'];
                    $field_factor = 1;
                    $field_unit = '';
                }
                switch ($field_def['base_type']['base_type_definition']['name']) {
                    case 'string':
                        $value = $this->reader->readString8($field_def['size']);
                        break;
                    case 'sint8':
                        $value = $this->reader->readInt8();
                        break;
                    case 'enum':
                    case 'uint8z':
                    case 'uint8':
                        $value = $this->reader->readUInt8();
                        break;
                    case 'sint16':
                        $value = $big_endian ? $this->reader->readInt16BE() : $this->reader->readInt16LE();
                        break;
                    case 'uint16z':
                    case 'uint16':
                        $value = $big_endian ? $this->reader->readUInt16BE() : $this->reader->readUInt16LE();
                        break;
                    case 'sint32':
                        $value = $big_endian ? $this->reader->readInt32BE() : $this->reader->readInt32LE();
                        break;
                    case 'uint32z':
                    case 'uint32':
                        $value = $big_endian ? $this->reader->readUInt32BE() : $this->reader->readUInt32LE();
                        break;
                    case 'float32':
                        $value = $big_endian ? $this->reader->readFloatBE() : $this->reader->readFloatLE();
                        break;
                    case 'float64':
                        $value = $big_endian ? $this->reader->readDoubleBE() : $this->reader->readDoubleLE();
                        break;
                    case 'byte':
                    default:
                        $value = $this->reader->read($field_def['size']);
                }
                if (is_numeric($value) && $field_factor > 0) {
                    $value *= $field_factor;
                }
                $data[$field_name] = array('value' => $value, 'unit' => $field_unit);
                if ($def['global_msg_number'] === 0 && $field_name === 'type') {
                    $this->file_type = $value;
                }
            }
            $this->records[] = $data;
        }
        if ($this->debug) {
            $style = 'padding:1px 3px;background:white;';
            $style2 = 'padding:1px 3px;background:lightgrey;';
            $style3 = 'padding:1px 3px;background:darkgrey;';
            static::$log->add('
				<tr>
					<td style="' . $style . '">' . intval($this->headerbits[7]) . '</td>
					<td style="' . $style2 . '">' . intval($this->headerbits[6]) . '</td>
					<td style="' . $style . '">' . intval($this->headerbits[5]) . '</td>
					<td style="' . $style . '">' . intval($this->headerbits[4]) . '</td>
					<td style="' . $style2 . '">' . intval($this->headerbits[3]) . '</td>
					<td style="' . $style2 . '">' . intval($this->headerbits[2]) . '</td>
					<td style="' . $style2 . '">' . intval($this->headerbits[1]) . '</td>
					<td style="' . $style2 . '">' . intval($this->headerbits[0]) . '</td>
					<td style="' . $style3 . '">' . $local_msg_type . '</td>
					<td style="' . $style3 . '">' . $def['global_msg_number'] . '</td>
					<td style="' . $style3 . '">' . $this->file_type . '</td>
						');
            if (isset($data)) {
                foreach ($data as $k => $d) {
                    $v = $d['value'];
                    if (stripos($k, 'time') !== false && stripos($k, 'total') === false) {
                        $v = strftime('%FT%H:%M:%S%z', \Fit\Data::timeToUnix($v));
                    } elseif ($d['unit'] === 'deg') {
                        $v = \Fit\Data::positionToDegrees($v);
                    }
                    static::$log->add('<td style="' . $style . '">' . $k . ': ' . $v . $d['unit'] . '</td>');
                }
            }
            static::$log->add('</tr>');
        }
    }