コード例 #1
0
ファイル: Package.php プロジェクト: hbustun/agilebill
 function _fromUrl($param, $saveparam = '')
 {
     if (!is_array($param) && preg_match('#^(http|ftp)://#', $param)) {
         $options = $this->_downloader->getOptions();
         $this->_type = 'url';
         $callback = $this->_downloader->ui ? array(&$this->_downloader, '_downloadCallback') : null;
         $this->_downloader->pushErrorHandling(PEAR_ERROR_RETURN);
         $file = $this->_downloader->downloadHttp($param, $this->_downloader->ui, $this->_downloader->getDownloadDir(), $callback);
         $this->_downloader->popErrorHandling();
         if (PEAR::isError($file)) {
             if (!empty($saveparam)) {
                 $saveparam = ", cannot download \"{$saveparam}\"";
             }
             $err = PEAR::raiseError('Could not download from "' . $param . '"' . $saveparam);
             return $err;
         }
         if ($this->_rawpackagefile) {
             require_once 'Archive/Tar.php';
             $tar =& new Archive_Tar($file);
             $packagexml = $tar->extractInString('package2.xml');
             if (!$packagexml) {
                 $packagexml = $tar->extractInString('package.xml');
             }
             if (str_replace(array("\n", "\r"), array('', ''), $packagexml) != str_replace(array("\n", "\r"), array('', ''), $this->_rawpackagefile)) {
                 if ($this->getChannel() == 'pear.php.net') {
                     // be more lax for the existing PEAR packages that have not-ok
                     // characters in their package.xml
                     $this->_downloader->log(0, 'CRITICAL WARNING: The "' . $this->getPackage() . '" package has invalid characters in its ' . 'package.xml.  The next version of PEAR may not be able to install ' . 'this package for security reasons.  Please open a bug report at ' . 'http://pear.php.net/package/' . $this->getPackage() . '/bugs');
                 } else {
                     return PEAR::raiseError('CRITICAL ERROR: package.xml downloaded does ' . 'not match value returned from xml-rpc');
                 }
             }
         }
         // whew, download worked!
         if (isset($options['downloadonly'])) {
             $pkg =& $this->getPackagefileObject($this->_config, $this->_downloader->debug);
         } else {
             $pkg =& $this->getPackagefileObject($this->_config, $this->_downloader->debug, $this->_downloader->getDownloadDir());
         }
         PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
         $pf =& $pkg->fromAnyFile($file, PEAR_VALIDATE_INSTALLING);
         PEAR::popErrorHandling();
         if (PEAR::isError($pf)) {
             if (is_array($pf->getUserInfo())) {
                 foreach ($pf->getUserInfo() as $err) {
                     if (is_array($err)) {
                         $err = $err['message'];
                     }
                     if (!isset($options['soft'])) {
                         $this->_downloader->log(0, "Validation Error: {$err}");
                     }
                 }
             }
             if (!isset($options['soft'])) {
                 $this->_downloader->log(0, $pf->getMessage());
             }
             $err = PEAR::raiseError('Download of "' . ($saveparam ? $saveparam : $param) . '" succeeded, but it is not a valid package archive');
             $this->_valid = false;
             return $err;
         }
         $this->_packagefile =& $pf;
         $this->setGroup('default');
         // install the default dependency group
         return $this->_valid = true;
     }
     return $this->_valid = false;
 }