private function _parse() { $this->torrentArray = Lms_BTransform::decode($this->source); $this->_isLoaded = $this->_isValidTorrentFile(); $this->_files = array(); if ($this->_isLoaded) { $this->_encoding = isset($this->torrentArray['encoding']) ? $this->torrentArray['encoding'] : 'UTF-8'; if (isset($this->torrentArray['info']['files'])) { $dirName = $this->torrentArray['info']['name']; foreach ($this->torrentArray['info']['files'] as $file) { $filePath = $dirName . $this->_dirSeparator . implode($this->_dirSeparator, $file['path']); $this->_files[] = array('path' => $filePath, 'size' => $file['length']); } } else { $filePath = $this->torrentArray['info']['name']; $fileSize = $this->torrentArray['info']['length']; $this->_files[] = array('path' => $filePath, 'size' => $fileSize); } } return $this->_isLoaded; }
/** * @access private * @static */ private static function _bdecodeRecursive($encodedStr, &$pos) { $encodedStrlen = strlen($encodedStr); if ($pos < 0 || $pos >= $encodedStrlen) { return NULL; } else { if ($encodedStr[$pos] == 'i') { $pos++; $numlen = strspn($encodedStr, '-0123456789', $pos); $spos = $pos; $pos += $numlen; if ($pos >= $encodedStrlen || $encodedStr[$pos] != 'e') { return NULL; } else { $pos++; return floatval(substr($encodedStr, $spos, $numlen)); } } elseif ($encodedStr[$pos] == 'd') { $pos++; $ret = array(); while ($pos < $encodedStrlen) { if ($encodedStr[$pos] == 'e') { $pos++; return $ret; } else { $key = Lms_BTransform::_bdecodeRecursive($encodedStr, $pos); if ($key === NULL) { return NULL; } else { $val = Lms_BTransform::_bdecodeRecursive($encodedStr, $pos); if ($val === NULL) { return NULL; } elseif (!is_array($key)) { $ret[$key] = $val; } } } } return NULL; } elseif ($encodedStr[$pos] == 'l') { $pos++; $ret = array(); while ($pos < $encodedStrlen) { if ($encodedStr[$pos] == 'e') { $pos++; return $ret; } else { $val = Lms_BTransform::_bdecodeRecursive($encodedStr, $pos); if ($val === NULL) { return NULL; } else { $ret[] = $val; } } } return NULL; } else { $numlen = strspn($encodedStr, '0123456789', $pos); $spos = $pos; $pos += $numlen; if ($pos >= $encodedStrlen || $encodedStr[$pos] != ':') { return NULL; } else { $vallen = intval(substr($encodedStr, $spos, $numlen)); $pos++; $val = substr($encodedStr, $pos, $vallen); if (strlen($val) != $vallen) { return NULL; } else { $pos += $vallen; return $val; } } } } }