$part) { $parents[] = array($part, md5($zpath."/".implode("/",array_slice($parts, 0, $index+1)))); } return $parents; } */ function stepString() { global $wopt_steps; global $wopt_currstep; return "Step ".$wopt_currstep." of ".$wopt_steps; } function shortlabel($pathname, $max = 99) { $basename = basename($pathname); $suffix = "(...).".pathinfo($basename,PATHINFO_EXTENSION); if (strlen($basename) > $max) { $return = substr($basename, 0, ($max-strlen($suffix))).$suffix; } else { $return = $basename; } return $return; } function human_filesize($bytes, $decimals = 2) { $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); $factor = floor((strlen($bytes) - 1) / 3); return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor]; } class plistParser extends XMLReader { public function parseString($string) { $this->XML($string); return $this->process(); } private function process() { $this->read(); if($this->nodeType !== XMLReader::DOC_TYPE || $this->name !== "plist") { throw new Exception(sprintf("Error parsing plist. nodeType: %d -- Name: %s", $this->nodeType, $this->name), 2); } if(!$this->next("plist") || $this->nodeType !== XMLReader::ELEMENT || $this->name !== "plist") { throw new Exception(sprintf("Error parsing plist. nodeType: %d -- Name: %s", $this->nodeType, $this->name), 3); } $plist = array(); while($this->read()) { if($this->nodeType == XMLReader::ELEMENT) { $plist[] = $this->parse_node(); } } if(count($plist) == 1 && $plist[0]) { return $plist[0]; } else { return $plist; } } private function parse_node() { if($this->nodeType !== XMLReader::ELEMENT) return; switch($this->name) { case 'data': return base64_decode($this->getNodeText()); break; case 'real': return floatval($this->getNodeText()); break; case 'string': return $this->getNodeText(); break; case 'integer': return intval($this->getNodeText()); break; case 'date': return $this->getNodeText(); break; case 'true': return true; break; case 'false': return false; break; case 'array': return $this->parse_array(); break; case 'dict': return $this->parse_dict(); break; default: throw new Exception(sprintf("Not a valid plist. %s is not a valid type", $this->name), 4); } } private function parse_dict() { $array = array(); $this->nextOfType(XMLReader::ELEMENT); do { if($this->nodeType !== XMLReader::ELEMENT || $this->name !== "key") { if(!$this->next("key")) { return $array; } } $key = $this->getNodeText(); $this->nextOfType(XMLReader::ELEMENT); $array[$key] = $this->parse_node(); $this->nextOfType(XMLReader::ELEMENT, XMLReader::END_ELEMENT); } while($this->nodeType && !$this->isNodeOfTypeName(XMLReader::END_ELEMENT, "dict")); return $array; } private function parse_array() { $array = array(); $this->nextOfType(XMLReader::ELEMENT); do { $array[] = $this->parse_node(); $this->nextOfType(XMLReader::ELEMENT, XMLReader::END_ELEMENT); } while($this->nodeType && !$this->isNodeOfTypeName(XMLReader::END_ELEMENT, "array")); return $array; } private function getNodeText() { $string = $this->readString(); $this->nextOfType(XMLReader::END_ELEMENT); return $string; } private function nextOfType() { $types = func_get_args(); $this->read(); while($this->nodeType && !(in_array($this->nodeType, $types))) { $this->read(); } } private function isNodeOfTypeName($type, $name) { return $this->nodeType === $type && $this->name === $name; } } function parseMediaInfo ($xml) { $xml = simplexml_load_string($xml); $data = array(); $data['version'] = (string) $xml['version']; foreach ($xml->File->track as $track) { $trackType = strtolower($track['type']); $trackId = isset($track['streamid']) ? $track['streamid'] : 1; $trackId = (string)$trackId; $trackData = []; foreach ($track as $rawKey => $rawVal) { $key = strtolower($rawKey); $val = (string)$rawVal; if ($key == 'stream_identifier') { continue; } if (!array_key_exists($key, $trackData)) { $trackData[$key] = array($val); } elseif (!in_array($val, $trackData[$key])) { $trackData[$key][] = $val; } } if ($trackType == 'general') { $data['file']['general'] = $trackData; } else { $data['file'][$trackType][$trackId] = $trackData; } } return $data; } ?>