[ Index ]
 

Code source de Typo3 4.1.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/typo3/mod/tools/em/ -> class.em_terconnection.php (source)

   1  <?php
   2  /* **************************************************************
   3  *  Copyright notice
   4  *
   5  *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
   6  *  (c) 2006 Karsten Dambekalns <karsten@typo3.org>
   7  *  All rights reserved
   8  *
   9  *  This script is part of the TYPO3 project. The TYPO3 project is
  10  *  free software; you can redistribute it and/or modify
  11  *  it under the terms of the GNU General Public License as published by
  12  *  the Free Software Foundation; either version 2 of the License, or
  13  *  (at your option) any later version.
  14  *
  15  *  The GNU General Public License can be found at
  16  *  http://www.gnu.org/copyleft/gpl.html.
  17  *  A copy is found in the textfile GPL.txt and important notices to the license
  18  *  from the author is found in LICENSE.txt distributed with these scripts.
  19  *
  20  *
  21  *  This script is distributed in the hope that it will be useful,
  22  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  23  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24  *  GNU General Public License for more details.
  25  *
  26  *  This copyright notice MUST APPEAR in all copies of the script!
  27  ***************************************************************/
  28  
  29  
  30  if (!defined('SOAP_1_2'))    {
  31      require_once ('class.nusoap.php');
  32  #    require_once('/usr/share/php/SOAP/Client.php');
  33  }
  34  require_once ('class.em_soap.php');
  35  
  36  /**
  37   * TER2 connection handling class for the TYPO3 Extension Manager.
  38   *
  39   * It contains methods for downloading and uploading extensions and related code
  40   *
  41   * @author Karsten Dambekalns <karsten@typo3.org>
  42   * @author    Kasper Skaarhoj <kasperYYYY@typo3.com>
  43   * @package TYPO3
  44   * @subpackage EM
  45   */
  46  class SC_mod_tools_em_terconnection {
  47      var $wsdlURL;
  48      var $emObj;
  49  
  50      /**
  51       * Fetches an extension from the given mirror
  52       *
  53       * @param    string        $extKey    Extension Key
  54       * @param    string        $version    Version to install
  55       * @param    string        $expectedMD5    Expected MD5 hash of extension file
  56       * @param    string        $mirrorURL    URL of mirror to use
  57       * @return    mixed        T3X data (array) or error message (string)
  58       */
  59  	function fetchExtension($extKey, $version, $expectedMD5, $mirrorURL) {
  60          $mirrorURL .= $extKey{0}.'/'.$extKey{1}.'/'.$extKey.'_'.$version.'.t3x';
  61          $t3x = t3lib_div::getURL($mirrorURL);
  62          $MD5 = md5($t3x);
  63  
  64          if($t3x===false) return 'The T3X file could not be fetched. Possible reasons: network problems, allow_url_fopen is off, curl is not enabled in Install tool.';
  65  
  66          if($MD5 == $expectedMD5) {
  67                  // Fetch and return:
  68              return $this->decodeExchangeData($t3x);
  69          } else {
  70              return 'Error: MD5 hash of downloaded file not as expected:<br />'.$MD5.' != '.$expectedMD5;
  71          }
  72      }
  73  
  74      /**
  75       * Fetches an extensions l10n file from the given mirror
  76       *
  77       * @param string $extKey    Extension Key
  78       * @param string $lang    The language code of the translation to fetch
  79       * @param string $mirrorURL    URL of mirror to use
  80       * @return mixed    Array containing l10n data or error message (string)
  81       */
  82  	function fetchTranslation($extKey, $lang, $mirrorURL) {
  83          $mirrorURL .= $extKey{0}.'/'.$extKey{1}.'/'.$extKey.'-l10n/'.$extKey.'-l10n-'.$lang.'.zip';
  84          $l10n = t3lib_div::getURL($mirrorURL);
  85  
  86          if($l10n !== false) {
  87              return array($l10n);
  88          } else {
  89              return 'Error: Translation could not be fetched.';
  90          }
  91      }
  92  
  93      /**
  94       * Fetches extension l10n status from the given mirror
  95       *
  96       * @param string     $extKey    Extension Key
  97       * @param string     $mirrorURL    URL of mirror to use
  98       * @return mixed    Array containing l10n status data or FALSE if no status could be fetched
  99       */
 100  	function fetchTranslationStatus($extKey, $mirrorURL) {
 101  
 102          $url = $mirrorURL . $extKey{0}.'/'.$extKey{1}.'/'.$extKey.'-l10n/'.$extKey.'-l10n.xml';
 103          $remote = t3lib_div::getURL($url);
 104  
 105          if($remote !== false) {
 106              $parsed = $this->emObj->xmlhandler->parseL10nXML($remote);
 107              return $parsed['languagePackIndex'];
 108          }
 109  
 110          return FALSE;
 111      }
 112  
 113      /**
 114       * Decode server data
 115       * This is information like the extension list, extension information etc., return data after uploads (new em_conf)
 116       *
 117       * @param    string        Data stream from remove server
 118       * @return    mixed        On success, returns an array with data array and stats array as key 0 and 1. Otherwise returns error string
 119       * @see fetchServerData(), processRepositoryReturnData()
 120       */
 121  	function decodeServerData($externalData)    {
 122          $parts = explode(':',$externalData,4);
 123          $dat = base64_decode($parts[2]);
 124              // compare hashes ignoring any leading whitespace. See bug #0000365.
 125          if (ltrim($parts[0])==md5($dat))    {
 126              if ($parts[1]=='gzcompress')    {
 127                  if (function_exists('gzuncompress'))    {
 128                      $dat = gzuncompress($dat);
 129                  } else return 'Decoding Error: No decompressor available for compressed content. gzuncompress() function is not available!';
 130              }
 131              $listArr = unserialize($dat);
 132  
 133              if (is_array($listArr))    {
 134                  return $listArr;
 135              } else {
 136                  return 'Error: Unserialized information was not an array - strange!';
 137              }
 138          } else return 'Error: MD5 hashes in T3X data did not match!';
 139      }
 140  
 141      /**
 142       * Decodes extension upload array.
 143       * This kind of data is when an extension is uploaded to TER
 144       *
 145       * @param    string        Data stream
 146       * @return    mixed        Array with result on success, otherwise an error string.
 147       */
 148  	function decodeExchangeData($str)    {
 149          $parts = explode(':',$str,3);
 150          if ($parts[1]=='gzcompress')    {
 151              if (function_exists('gzuncompress'))    {
 152                  $parts[2] = gzuncompress($parts[2]);
 153              } else return 'Decoding Error: No decompressor available for compressed content. gzcompress()/gzuncompress() functions are not available!';
 154          }
 155          if (md5($parts[2]) == $parts[0])    {
 156              $output = unserialize($parts[2]);
 157              if (is_array($output))    {
 158                  return array($output,'');
 159              } else return 'Error: Content could not be unserialized to an array. Strange (since MD5 hashes match!)';
 160          } else return '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)';
 161      }
 162  
 163  
 164      /**
 165       * Encodes extension upload array
 166       *
 167       * @param    array        Array containing extension
 168       * @return    string        Content stream
 169       */
 170  	function makeUploadDataFromArray($uploadArray)    {
 171          if (is_array($uploadArray))    {
 172              $serialized = serialize($uploadArray);
 173              $md5 = md5($serialized);
 174  
 175              $content = $md5.':';
 176              $content.= 'gzcompress:';
 177              $content.= gzcompress($serialized);
 178          }
 179          return $content;
 180      }
 181  
 182      /**
 183       * [Describe function...]
 184       *
 185       * @param    [type]        $em: ...
 186       * @return    [type]        ...
 187       */
 188  	function uploadToTER($em) {
 189          $uArr = $this->emObj->makeUploadArray($em['extKey'],$em['extInfo']);
 190          if(!is_array($uArr)) return $uArr;
 191  
 192              // Render new version number:
 193          $newVersionBase = $em['extInfo']['EM_CONF']['version'];
 194          switch((string)$em['upload']['mode']) {
 195              case 'new_dev':
 196                  $cmd='dev';
 197                  break;
 198              case 'new_sub':
 199                  $cmd='sub';
 200                  break;
 201              case 'new_main':
 202                  $cmd='main';
 203                  break;
 204              case 'custom':
 205                  $newVersionBase = $em['upload']['version'];
 206              case 'latest':
 207              default:
 208                  $cmd='';
 209                  break;
 210          }
 211          $versionArr = $this->emObj->renderVersion($newVersionBase, $cmd);
 212          $em['version'] = $versionArr['version'];
 213  
 214              // Create dependency / conflict information:
 215          $dependenciesArr = array ();
 216          $extKeysArr = $uArr['EM_CONF']['constraints']['depends'];
 217  
 218          if (is_array($extKeysArr)) {
 219              foreach ($extKeysArr as $extKey => $version) {
 220                  if (strlen($extKey)) {
 221                      $dependenciesArr [] = array (
 222                          'kind' => 'depends',
 223                          'extensionKey' => utf8_encode($extKey),
 224                          'versionRange' => utf8_encode($version),
 225                      );
 226                  }
 227              }
 228          }
 229  
 230          $extKeysArr = $uArr['EM_CONF']['constraints']['conflicts'];
 231          if (is_array($extKeysArr)) {
 232              foreach ($extKeysArr as $extKey => $version) {
 233                  if (strlen($extKey)) {
 234                      $dependenciesArr [] = array (
 235                          'kind' => 'conflicts',
 236                          'extensionKey' => utf8_encode($extKey),
 237                          'versionRange' => utf8_encode($version),
 238                      );
 239                  }
 240              }
 241          }
 242  
 243              // Compile data for SOAP call:
 244          $accountData = array(
 245              'username' => $em['user']['fe_u'],
 246              'password' => $em['user']['fe_p']
 247          );
 248          $extensionData = array (
 249              'extensionKey' => utf8_encode($em['extKey']),
 250              'version' => utf8_encode($em['version']),
 251              'metaData' => array (
 252                  'title' => utf8_encode($uArr['EM_CONF']['title']),
 253                  'description' => utf8_encode($uArr['EM_CONF']['description']),
 254                  'category' => utf8_encode($uArr['EM_CONF']['category']),
 255                  'state' => utf8_encode($uArr['EM_CONF']['state']),
 256                  'authorName' => utf8_encode($uArr['EM_CONF']['author']),
 257                  'authorEmail' => utf8_encode($uArr['EM_CONF']['author_email']),
 258                  'authorCompany' => utf8_encode($uArr['EM_CONF']['author_company']),
 259              ),
 260              'technicalData' => array (
 261                  'dependencies' => $dependenciesArr,
 262                  'loadOrder' => utf8_encode($uArr['EM_CONF']['loadOrder']),
 263                  'uploadFolder' => (boolean) intval($uArr['EM_CONF']['uploadfolder']),
 264                  'createDirs' => utf8_encode($uArr['EM_CONF']['createDirs']),
 265                  'shy' => (boolean) intval($uArr['EM_CONF']['shy']),
 266                  'modules' => utf8_encode($uArr['EM_CONF']['module']),
 267                  'modifyTables' => utf8_encode($uArr['EM_CONF']['modify_tables']),
 268                  'priority' => utf8_encode($uArr['EM_CONF']['priority']),
 269                  'clearCacheOnLoad' => (boolean) intval($uArr['EM_CONF']['clearCacheOnLoad']),
 270                  'lockType' => utf8_encode($uArr['EM_CONF']['lockType']),
 271              ),
 272              'infoData' => array(
 273                  'codeLines' => intval($uArr['misc']['codelines']),
 274                  'codeBytes' => intval($uArr['misc']['codebytes']),
 275                  'codingGuidelinesCompliance' => utf8_encode($uArr['EM_CONF']['CGLcompliance']),
 276                  'codingGuidelinesComplianceNotes' => utf8_encode($uArr['EM_CONF']['CGLcompliance_note']),
 277                  'uploadComment' => utf8_encode($em['upload']['comment']),
 278                  'techInfo' => $uArr['techInfo'],
 279              ),
 280          );
 281  
 282          $filesData = array();
 283          foreach ($uArr['FILES'] as $filename => $infoArr) {
 284              $content = (!defined('SOAP_1_2') && class_exists('soapclient')) ? base64_encode($infoArr['content']) : $infoArr['content']; // bug in NuSOAP - no automatic encoding
 285              $filesData['fileData'][] = array (
 286                  'name' => utf8_encode($infoArr['name']),
 287                  'size' => intval($infoArr['size']),
 288                  'modificationTime' => intval($infoArr['mtime']),
 289                  'isExecutable' => intval($infoArr['is_executable']),
 290                  'content' => $content,
 291                  'contentMD5' => $infoArr['content_md5'],
 292              );
 293          }
 294  
 295          $soap = t3lib_div::makeInstance('em_soap');
 296          $soap->init(array('wsdl'=>$this->wsdlURL,'soapoptions'=> array('trace'=>1,'exceptions'=>0)));
 297          $response = $soap->call('uploadExtension', array('accountData' => $accountData, 'extensionData' => $extensionData, 'filesData' => $filesData));
 298  
 299          if($response===false) {
 300              switch(true) {
 301              case is_string($soap->error):
 302                  return $soap->error;
 303                  break;
 304              default:
 305                  return $soap->error->faultstring;
 306              }
 307          }
 308  
 309          return $response;
 310      }
 311  }
 312  ?>


Généré le : Sun Nov 25 17:13:16 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics