TYPO3 CMS  TYPO3_6-2
TerUtility.php
Go to the documentation of this file.
1 <?php
3 
17 
26 class TerUtility {
27 
31  public $wsdlUrl;
32 
43  public function fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl) {
44  $extensionPath = \TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($extensionKey);
45  $mirrorUrl .= $extensionPath[0] . '/' . $extensionPath[1] . '/' . $extensionPath . '_' . $version . '.t3x';
46  $t3x = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($mirrorUrl, 0, array(TYPO3_user_agent));
47  $md5 = md5($t3x);
48  if ($t3x === FALSE) {
49  throw new ExtensionManagerException(sprintf('The T3X file "%s" could not be fetched. Possible reasons: network problems, allow_url_fopen is off,' . ' cURL is not enabled in Install Tool.', $mirrorUrl), 1334426097);
50  }
51  if ($md5 === $expectedMd5) {
52  // Fetch and return:
53  $extensionData = $this->decodeExchangeData($t3x);
54  } else {
55  throw new ExtensionManagerException('Error: MD5 hash of downloaded file not as expected:<br />' . $md5 . ' != ' . $expectedMd5, 1334426098);
56  }
57  return $extensionData;
58  }
59 
72  public function decodeServerData($externalData) {
73  $parts = explode(':', $externalData, 4);
74  $dat = base64_decode($parts[2]);
75  gzuncompress($dat);
76  // compare hashes ignoring any leading whitespace. See bug #0000365.
77  if (ltrim($parts[0]) == md5($dat)) {
78  if ($parts[1] == 'gzcompress') {
79  if (function_exists('gzuncompress')) {
80  $dat = gzuncompress($dat);
81  } else {
82  throw new ExtensionManagerException('Decoding Error: No decompressor available for compressed content. gzuncompress() function is not available!', 1342859463);
83  }
84  }
85  $listArr = unserialize($dat);
86  if (!is_array($listArr)) {
87  throw new ExtensionManagerException('Error: Unserialized information was not an array - strange!', 1342859489);
88  }
89  } else {
90  throw new ExtensionManagerException('Error: MD5 hashes in T3X data did not match!', 1342859505);
91  }
92  return $listArr;
93  }
94 
103  public function decodeExchangeData($stream) {
104  $parts = explode(':', $stream, 3);
105  if ($parts[1] == 'gzcompress') {
106  if (function_exists('gzuncompress')) {
107  $parts[2] = gzuncompress($parts[2]);
108  } else {
109  throw new ExtensionManagerException('Decoding Error: No decompressor available for compressed content. gzcompress()/gzuncompress() ' . 'functions are not available!', 1344761814);
110  }
111  }
112  if (md5($parts[2]) === $parts[0]) {
113  $output = unserialize($parts[2]);
114  if (!is_array($output)) {
115  throw new ExtensionManagerException('Error: Content could not be unserialized to an array. Strange (since MD5 hashes match!)', 1344761938);
116  }
117  } else {
118  throw new ExtensionManagerException('Error: MD5 mismatch. Maybe the extension file was downloaded and saved as a text file by the ' . 'browser and thereby corrupted!? (Always select "All" filetype when saving extensions)', 1344761991);
119  }
120  return $output;
121  }
122 
123 }
fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl)
Definition: TerUtility.php:43
static getUrl($url, $includeHeader=0, $requestHeaders=FALSE, &$report=NULL)