/** * Reads and constructs the boxes found within this box. * * @todo Does not parse iTunes internal ---- boxes. */ protected function constructBoxes($defaultclassname = "ISO14496_Box") { $base = $this->getOption("base", ""); if ($this->getType() != "file") self::$_path[] = $this->getType(); $path = implode(self::$_path, "."); while (true) { $offset = $this->_reader->getOffset(); if ($offset >= $this->_offset + $this->_size) break; $size = $this->_reader->readUInt32BE(); $type = rtrim($this->_reader->read(4), " "); if ($size == 1) $size = $this->_reader->readInt64BE(); if ($size == 0) $size = $this->_reader->getSize() - $offset; if (preg_match("/^\xa9?[a-z0-9]{3,4}$/i", $type) && substr($base, 0, min(strlen($base), strlen ($tmp = $path . ($path ? "." : "") . $type))) == substr($tmp, 0, min(strlen($base), strlen($tmp)))) { $this->_reader->setOffset($offset); if (@fopen($filename = "ISO14496/Box/" . strtoupper($type) . ".php", "r", true) !== false) require_once($filename); if (class_exists($classname = "ISO14496_Box_" . strtoupper($type))) $box = new $classname($this->_reader, $this->_options); else $box = new $defaultclassname($this->_reader, $this->_options); $box->setParent($this); if (!isset($this->_boxes[$box->getType()])) $this->_boxes[$box->getType()] = array(); $this->_boxes[$box->getType()][] = $box; } $this->_reader->setOffset($offset + $size); } array_pop(self::$_path); }
/** * Reads and constructs the boxes found within this box. * * @todo Does not parse iTunes internal ---- boxes. */ protected final function constructBoxes($defaultclassname = 'Zend_Media_Iso14496_Box') { $base = $this->getOption('base', ''); if ($this->getType() != 'file') { self::$_path[] = $this->getType(); } $path = implode(self::$_path, '.'); while (true) { $offset = $this->_reader->getOffset(); if ($offset >= $this->_offset + $this->_size) { break; } $size = $this->_reader->readUInt32BE(); $type = rtrim($this->_reader->read(4), ' '); if ($size == 1) { $size = $this->_reader->readInt64BE(); } if ($size == 0) { $size = $this->_reader->getSize() - $offset; } if (preg_match("/^©?[a-z0-9]{3,4}\$/i", $type) && substr($base, 0, min(strlen($base), strlen($tmp = $path . ($path ? '.' : '') . $type))) == substr($tmp, 0, min(strlen($base), strlen($tmp)))) { $this->_reader->setOffset($offset); if (@fopen($filename = 'Zend/Media/Iso14496/Box/' . ucfirst($type) . '.php', 'r', true) !== false) { require_once $filename; } if (class_exists($classname = 'Zend_Media_Iso14496_Box_' . ucfirst($type))) { $box = new $classname($this->_reader, $this->_options); } else { $box = new $defaultclassname($this->_reader, $this->_options); } $box->setParent($this); if (!isset($this->_boxes[$box->getType()])) { $this->_boxes[$box->getType()] = array(); } $this->_boxes[$box->getType()][] = $box; } $this->_reader->setOffset($offset + $size); } array_pop(self::$_path); }
/** * Returns the recognized MIME type/description of the given file. The type * is determined by the content using magic bytes characteristic for the * particular file type. * * If the type could not be found, the function returns the default value, or * <var>false</var>. * * @param string $filename The file path whose type to determine. * @param string $default The default value. * @return string|false */ public function getType($filename, $default = false) { $reader = new Reader($filename); $parentOffset = 0; foreach (preg_split("/^/m", $this->_magic) as $line) { $chunks = array(); if (!preg_match("/^(?P<Dependant>>?)(?P<Byte>\d+)\s+(?P<MatchType>\S+)" . "\s+(?P<MatchData>\S+)(?:\s+(?P<MIMEType>[a-z]+\/[a-z-" . "0-9]+)?(?:\s+(?P<Description>.+))?)?$/", $line, $chunks)) continue; if ($chunks["Dependant"]) { $reader->setOffset($parentOffset); $reader->skip($chunks["Byte"]); } else $reader->setOffset($parentOffset = $chunks["Byte"]); $matchType = strtolower($chunks["MatchType"]); $matchData = preg_replace (array("/\\\\ /", "/\\\\\\\\/", "/\\\\([0-7]{1,3})/e", "/\\\\x([0-9A-Fa-f]{1,2})/e", "/0x([0-9A-Fa-f]+)/e"), array(" ", "\\\\", "pack(\"H*\", base_convert(\"$1\", 8, 16));", "pack(\"H*\", \"$1\");", "hexdec(\"$1\");"), $chunks["MatchData"]); switch ($matchType) { case "byte": // single character $data = $reader->readInt8(); break; case "short": // machine-order 16-bit integer $data = $reader->readInt16(); break; case "long": // machine-order 32-bit integer $data = $reader->readInt32(); break; case "string": // arbitrary-length string $data = $reader->readString8(strlen($matchData)); break; case "date": // long integer date (seconds since Unix epoch/1970) $data = $reader->readInt64BE(); break; case "beshort": // big-endian 16-bit integer $data = $reader->readUInt16BE(); break; case "belong": // big-endian 32-bit integer case "bedate": // big-endian 32-bit integer date $data = $reader->readUInt32BE(); break; case "leshort": // little-endian 16-bit integer $data = $reader->readUInt16LE(); break; case "lelong": // little-endian 32-bit integer case "ledate": // little-endian 32-bit integer date $data = $reader->readUInt32LE(); break; default: $data = null; break; } if (strcmp($data, $matchData) == 0) { if (!empty($chunks["MIMEType"])) return $chunks["MIMEType"]; if (!empty($chunks["Description"])) return $chunks["Description"]; } } return $default; }