str('url');
$this->download($plugin_url, $this->overwrite);
return '';
}
/**
* Print results of the download
*/
function html() {
parent::html();
ptln('
');
ptln('
'.$this->lang['downloading'].'
');
if ($this->manager->error) {
ptln('
'.str_replace("\n","
",$this->manager->error).'
');
} else if (count($this->downloaded) == 1) {
ptln('
'.sprintf($this->lang['downloaded'],$this->downloaded[0]).'
');
} else if (count($this->downloaded)) { // more than one plugin in the download
ptln('
'.$this->lang['downloads'].'
');
ptln('
');
foreach ($this->downloaded as $plugin) {
ptln(''.$plugin.'
',2);
}
ptln('
');
} else { // none found in download
ptln('
'.$this->lang['download_none'].'
');
}
ptln('
');
}
/**
* Process the downloaded file
*/
function download($url, $overwrite=false) {
// check the url
$matches = array();
if (!preg_match("/[^\/]*$/", $url, $matches) || !$matches[0]) {
$this->manager->error = $this->lang['error_badurl']."\n";
return false;
}
$file = $matches[0];
if (!($tmp = io_mktmpdir())) {
$this->manager->error = $this->lang['error_dircreate']."\n";
return false;
}
if (!$file = io_download($url, "$tmp/", true, $file, 0)) {
$this->manager->error = sprintf($this->lang['error_download'],$url)."\n";
}
if (!$this->manager->error && !$this->decompress("$tmp/$file", $tmp)) {
$this->manager->error = sprintf($this->lang['error_decompress'],$file)."\n";
}
// search $tmp for the folder(s) that has been created
// move the folder(s) to lib/plugins/
if (!$this->manager->error) {
$result = array('old'=>array(), 'new'=>array());
if($this->find_folders($result,$tmp)){
// choose correct result array
if(count($result['new'])){
$install = $result['new'];
}else{
$install = $result['old'];
}
// now install all found items
foreach($install as $item){
// where to install?
if($item['type'] == 'template'){
$target = DOKU_INC.'lib/tpl/'.$item['base'];
}else{
$target = DOKU_INC.'lib/plugins/'.$item['base'];
}
// check to make sure we aren't overwriting anything
if (!$overwrite && @file_exists($target)) {
// remember our settings, ask the user to confirm overwrite, FIXME
continue;
}
$instruction = @file_exists($target) ? 'update' : 'install';
// copy action
if ($this->dircopy($item['tmp'], $target)) {
$this->downloaded[] = $item['base'];
$this->plugin_writelog($target, $instruction, array($url));
} else {
$this->manager->error .= sprintf($this->lang['error_copy']."\n", $item['base']);
}
}
} else {
$this->manager->error = $this->lang['error']."\n";
}
}
// cleanup
if ($tmp) $this->dir_delete($tmp);
if (!$this->manager->error) {
msg(sprintf($this->lang['packageinstalled'], count($this->downloaded), join(',',$this->downloaded)),1);
$this->refresh();
return true;
}
return false;
}
/**
* Find out what was in the extracted directory
*
* Correct folders are searched recursively using the "*.info.txt" configs
* as indicator for a root folder. When such a file is found, it's base
* setting is used (when set). All folders found by this method are stored
* in the 'new' key of the $result array.
*
* For backwards compatibility all found top level folders are stored as
* in the 'old' key of the $result array.
*
* When no items are found in 'new' the copy mechanism should fall back
* the 'old' list.
*
* @author Andreas Gohr