mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-06 15:14:58 +00:00
add new method getExtensionFromRepository(), support for proxy
This commit is contained in:
parent
6454f466cf
commit
02dd7989fb
|
@ -103,10 +103,13 @@ class SeedDMS_Extension_Mgr {
|
|||
* configuration file if it does not exist and the extension dir
|
||||
* is given
|
||||
*/
|
||||
public function __construct($extdir = '', $cachedir = '', $reposurl = '') { /* {{{ */
|
||||
public function __construct($extdir = '', $cachedir = '', $reposurl = '', $proxyurl='', $proxyuser='', $proxypass='') { /* {{{ */
|
||||
$this->cachedir = $cachedir;
|
||||
$this->extdir = $extdir;
|
||||
$this->reposurl = $reposurl;
|
||||
$this->proxyurl = $proxyurl;
|
||||
$this->proxyuser = $proxyuser;
|
||||
$this->proxypass = $proxypass;
|
||||
$this->extconf = array();
|
||||
if($extdir) {
|
||||
if(!file_exists($this->getExtensionsConfFile())) {
|
||||
|
@ -119,6 +122,29 @@ class SeedDMS_Extension_Mgr {
|
|||
}
|
||||
} /* }}} */
|
||||
|
||||
private function getStreamContext() { /* {{{ */
|
||||
if(!$this->proxyurl)
|
||||
return null;
|
||||
$url = parse_url($this->proxyurl);
|
||||
$opts = [
|
||||
$url['scheme'] => [
|
||||
'proxy' => 'tcp://'.$url['host'].($url['port'] ? ':'.$url['port'] : ''),
|
||||
'request_fulluri' => true,
|
||||
]
|
||||
];
|
||||
if($this->proxyuser && $this->proxypass) {
|
||||
$auth = base64_encode($this->proxyurl.':'.$this->proxypass);
|
||||
$opts[$url['scheme']] = [
|
||||
'header' => [
|
||||
'Proxy-Authorization: Basic '.$auth
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$context = stream_context_create($opts);
|
||||
return $context;
|
||||
} /* }}} */
|
||||
|
||||
protected function getExtensionsConfFile() { /* {{{ */
|
||||
return $this->cachedir."/extensions.php";
|
||||
} /* }}} */
|
||||
|
@ -539,7 +565,7 @@ class SeedDMS_Extension_Mgr {
|
|||
public function updateExtensionList($version='', $force=false) { /* {{{ */
|
||||
if($this->reposurl) {
|
||||
if(!file_exists($this->cachedir."/".self::repos_list_file) || $force) {
|
||||
if($file = @file_get_contents($this->reposurl.($version ? '?seeddms_version='.$version : ''))) {
|
||||
if($file = @file_get_contents($this->reposurl.($version ? '?seeddms_version='.$version : ''), false, $this->getStreamContext())) {
|
||||
if(is_array($http_response_header)) {
|
||||
$parts=explode(' ',$http_response_header[0]);
|
||||
if(count($parts)>1) //HTTP/1.0 <code> <text>
|
||||
|
@ -559,6 +585,18 @@ class SeedDMS_Extension_Mgr {
|
|||
}
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Download an extension from the repository
|
||||
*
|
||||
* @param string $file filename of extension
|
||||
*/
|
||||
public function getExtensionFromRepository($file) { /* {{{ */
|
||||
$content = file_get_contents($this->reposurl."/".$file, false, $this->getStreamContext());
|
||||
$tmpfile = tempnam(sys_get_temp_dir(), '');
|
||||
file_put_contents($tmpfile, $content);
|
||||
return $tmpfile;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Return last error message
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user