add import from repository

This commit is contained in:
Uwe Steinmann 2018-03-13 14:38:49 +01:00
parent 0554dab3ae
commit 52fc4cbe69
4 changed files with 102 additions and 54 deletions

View File

@ -17,12 +17,7 @@ require_once "inc.Version.php";
require_once "inc.Utils.php";
$extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir);
$extconffile = $extMgr->getExtensionsConfFile();
if(!file_exists($extconffile)) {
$extMgr->createExtensionConf();
}
$EXT_CONF = array();
include($extconffile);
$EXT_CONF = $extMgr->getExtensionConfiguration();
$version = new SeedDMS_Version;
@ -31,7 +26,7 @@ foreach($EXT_CONF as $extname=>$extconf) {
/* check for requirements */
if(!empty($extconf['constraints']['depends']['seeddms'])) {
$t = explode('-', $extconf['constraints']['depends']['seeddms'], 2);
if(cmpVersion($t[0], $version->version()) > 0 || ($t[1] && cmpVersion($t[1], $version->version()) < 0))
if(SeedDMS_Extension_Mgr::cmpVersion($t[0], $version->version()) > 0 || ($t[1] && SeedDMS_Extension_Mgr::cmpVersion($t[1], $version->version()) < 0))
$extconf['disable'] = true;
}
}
@ -48,7 +43,7 @@ foreach($EXT_CONF as $extname=>$extconf) {
if(file_exists($langfile)) {
unset($__lang);
include($langfile);
if($__lang) {
if(isset($__lang) && $__lang) {
foreach($__lang as $lang=>&$data) {
if(isset($GLOBALS['LANG'][$lang]))
$GLOBALS['LANG'][$lang] = array_merge($GLOBALS['LANG'][$lang], $data);

View File

@ -57,17 +57,18 @@ if ($action == "download") {
}
add_log_line();
} /* }}} */
elseif ($action == "refresh") {
elseif ($action == "refresh") { /* {{{ */
$extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir);
$extMgr->createExtensionConf();
$controller->setParam('extmgr', $extMgr);
if (!$controller($_POST)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_extension_refresh')));
add_log_line();
header("Location:../out/out.ExtensionMgr.php");
}
elseif ($action == "upload") {
} /* }}} */
elseif ($action == "upload") { /* {{{ */
if($_FILES['userfile']['error']) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
@ -80,9 +81,32 @@ elseif ($action == "upload") {
if (!$controller($_POST)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_extension_import')));
add_log_line();
header("Location:../out/out.ExtensionMgr.php");
}
} /* }}} */
elseif ($action == "import") { /* {{{ */
if(!$_POST['url']) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
$reposurl = 'http://seeddms.steinmann.cx/repository';
$content = file_get_contents($reposurl."/".$_POST['url']);
$file = tempnam(sys_get_temp_dir(), '');
file_put_contents($file, $content);
$extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir);
$controller->setParam('extmgr', $extMgr);
$controller->setParam('file', $file);
$_POST['action'] = 'upload';
if (!$controller($_POST)) {
unlink($file);
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
unlink($file);
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_extension_upload')));
add_log_line();
header("Location:../out/out.ExtensionMgr.php");
} /* }}} */
?>

View File

@ -33,12 +33,14 @@ if (!$user->isAdmin()) {
}
$v = new SeedDMS_Version;
$extmgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir);
$currenttab = 'installed';
if($view) {
$view->setParam('httproot', $settings->_httpRoot);
$view->setParam('version', $v);
$view->setParam('partitionsize', 200000);
$view->setParam('maxuploadsize', 2000000);
$view->setParam('extmgr', $extmgr);
$view->setParam('currenttab', $currenttab);
$view($_GET);
exit;
}

View File

@ -28,9 +28,6 @@ require_once("class.Bootstrap.php");
class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
function js() { /* {{{ */
$partitionsize = $this->params['partitionsize'];
$maxuploadsize = $this->params['maxuploadsize'];
header('Content-Type: application/javascript');
?>
$(document).ready( function() {
@ -57,6 +54,11 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
});
*/
});
$('a.import').click(function(ev){
var element = $(this);
$('#'+element.data('extname')+'-import').submit();
});
});
<?php
} /* }}} */
@ -66,6 +68,10 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
$user = $this->params['user'];
$httproot = $this->params['httproot'];
$version = $this->params['version'];
$extmgr = $this->params['extmgr'];
$currenttab = $this->params['currenttab'];
$reposurl = 'http://seeddms.steinmann.cx/repository';
$this->htmlStartPage(getMLText("admin_tools"));
$this->globalNavigation();
@ -87,12 +93,18 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
<div class="control-group">
<label class="control-label" for="enddate"></label>
<div class="controls">
<button id="upload" type="_submit" class="btn"><i class="icon-upload"></i> <?= getMLText("upload_extension"); ?></button>
<button id="upload" type="_submit" class="btn"><i class="icon-upload"></i> <?= getMLText("impor_extension"); ?></button>
</div>
</div>
</form>
</div>
<div class="span8">
<ul class="nav nav-tabs" id="extensionstab">
<li class="<?php if(!$currenttab || $currenttab == 'installed') echo 'active'; ?>"><a data-target="#installed" data-toggle="tab"><?php printMLText('extensions_installed'); ?></a></li>
<li class="<?php if($currenttab == 'repository') echo 'active'; ?>"><a data-target="#repository" data-toggle="tab"><?php printMLText('extensions_repository'); ?></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane <?php if(!$currenttab || $currenttab == 'installed') echo 'active'; ?>" id="installed">
<?php
// $this->contentContainerStart();
echo "<table class=\"table _table-condensed\">\n";
@ -101,43 +113,14 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
print "<th>".getMLText('name')."</th>\n";
print "<th>".getMLText('version')."</th>\n";
print "<th>".getMLText('author')."</th>\n";
print "</tr></thead>\n";
print "<th></th>\n";
print "</tr></thead><tbody>\n";
$errmsgs = array();
foreach($GLOBALS['EXT_CONF'] as $extname=>$extconf) {
$errmsgs = array();
if(!isset($extconf['disable']) || $extconf['disable'] == false) {
/* check dependency on specific seeddms version */
if(!isset($extconf['constraints']['depends']['seeddms']))
$errmsgs[] = "Missing dependency on SeedDMS";
if(!isset($extconf['constraints']['depends']['php']))
$errmsgs[] = "Missing dependency on PHP";
if(isset($extconf['constraints']['depends'])) {
foreach($extconf['constraints']['depends'] as $dkey=>$dval) {
switch($dkey) {
case 'seeddms':
$tmp = explode('-', $dval, 2);
if(cmpVersion($tmp[0], $version->version()) > 0 || ($tmp[1] && cmpVersion($tmp[1], $version->version()) < 0))
$errmsgs[] = sprintf("Incorrect SeedDMS version (needs version %s)", $extconf['constraints']['depends']['seeddms']);
break;
case 'php':
$tmp = explode('-', $dval, 2);
if(cmpVersion($tmp[0], phpversion()) > 0 || ($tmp[1] && cmpVersion($tmp[1], phpversion()) < 0))
$errmsgs[] = sprintf("Incorrect PHP version (needs version %s)", $extconf['constraints']['depends']['php']);
break;
default:
$tmp = explode('-', $dval, 2);
if(isset($GLOBALS['EXT_CONF'][$dkey]['version'])) {
if(cmpVersion($tmp[0], $GLOBALS['EXT_CONF'][$dkey]['version']) > 0 || ($tmp[1] && cmpVersion($tmp[1], $GLOBALS['EXT_CONF'][$dkey]['version']) < 0))
$errmsgs[] = sprintf("Incorrect version of extension '%s' (needs version '%s' but provides '%s')", $dkey, $dval, $GLOBALS['EXT_CONF'][$dkey]['version']);
} else {
$errmsgs[] = sprintf("Missing extension or version for '%s'", $dkey);
}
break;
}
}
}
$extmgr->checkExtension($extname);
$errmsgs = $extmgr->getErrorMsgs();
if($errmsgs)
echo "<tr class=\"error\">";
else
@ -146,23 +129,25 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
echo "<tr class=\"warning\">";
echo "<td>";
if($extconf['icon'])
echo "<img src=\"".$httproot."ext/".$extname."/".$extconf['icon']."\">";
echo "<img src=\"".$httproot."ext/".$extname."/".$extconf['icon']."\" alt=\"".$extname."\" title=\"".$extname."\">";
echo "</td>";
echo "<td>".$extconf['title']."<br /><small>".$extconf['description']."</small>";
if($errmsgs)
echo "<div><img src=\"".$this->getImgPath("attention.gif")."\"> ".implode('<br /><img src="'.$this->getImgPath("attention.gif").'"> ', $errmsgs)."</div>";
echo "</td>";
echo "<td nowrap>".$extconf['version']."<br /><small>".$extconf['releasedate']."</small>";
echo "</td>";
echo "<td nowrap><a href=\"mailto:".$extconf['author']['email']."\">".$extconf['author']['name']."</a><br /><small>".$extconf['author']['company']."</small></td>";
echo "<td nowrap>";
echo "<div class=\"list-action\">";
if($extconf['config'])
echo "<a href=\"../out/out.Settings.php?currenttab=extensions#".$extname."\" title=\"".getMLText('configure_extension')."\"><i class=\"icon-cogs\"></i></a>";
echo "<form style=\"display: inline-block; margin: 0px;\" method=\"post\" action=\"../op/op.ExtensionMgr.php\" id=\"".$extname."-download\">".createHiddenFieldWithKey('extensionmgr')."<input type=\"hidden\" name=\"action\" value=\"download\" /><input type=\"hidden\" name=\"extname\" value=\"".$extname."\" /><a class=\"download\" data-extname=\"".$extname."\" title=\"".getMLText('download_extension')."\"><i class=\"icon-download\"></i></a></form>";
echo "</div>";
echo "</td>";
echo "<td nowrap><a href=\"mailto:".$extconf['author']['email']."\">".$extconf['author']['name']."</a><br /><small>".$extconf['author']['company']."</small></td>";
echo "</tr>\n";
}
echo "</table>\n";
echo "</tbody></table>\n";
?>
<form action="../op/op.ExtensionMgr.php" name="form1" method="post">
<?php echo createHiddenFieldWithKey('extensionmgr'); ?>
@ -172,6 +157,48 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
<?php
// $this->contentContainerEnd();
?>
</div>
<div class="tab-pane <?php if($currenttab == 'repository') echo 'active'; ?>" id="repository">
<?php
echo "<table class=\"table _table-condensed\">\n";
print "<thead>\n<tr>\n";
print "<th></th>\n";
print "<th>".getMLText('name')."</th>\n";
print "<th>".getMLText('version')."</th>\n";
print "<th>".getMLText('author')."</th>\n";
print "<th></th>\n";
print "</tr></thead><tbody>\n";
$list = $extmgr->importExtensionList($reposurl);
foreach($list as $e) {
if($e[0] != '#') {
$re = json_decode($e);
$needsupdate = !isset($GLOBALS['EXT_CONF'][$re->name]) || SeedDMS_Extension_Mgr::cmpVersion($re->version, $GLOBALS['EXT_CONF'][$re->name]['version']) > 0;
echo "<tr";
if(isset($GLOBALS['EXT_CONF'][$re->name])) {
if($needsupdate)
echo " class=\"warning\"";
else
echo " class=\"success\"";
}
echo ">";
echo "<td></td>";
echo "<td>".$re->title."<br /><small>".$re->description."</small></td>";
echo "<td nowrap>".$re->version."<br /><small>".$re->releasedate."</small></td>";
echo "<td nowrap>".$re->author->name."<br /><small>".$re->author->company."</small></td>";
echo "<td nowrap>";
echo "<div class=\"list-action\">";
if($needsupdate)
echo "<form style=\"display: inline-block; margin: 0px;\" method=\"post\" action=\"../op/op.ExtensionMgr.php\" id=\"".$extname."-import\">".createHiddenFieldWithKey('extensionmgr')."<input type=\"hidden\" name=\"action\" value=\"import\" /><input type=\"hidden\" name=\"url\" value=\"".$re->filename."\" /><a class=\"import\" data-extname=\"".$extname."\" title=\"".getMLText('import_extension')."\"><i class=\"icon-download\"></i></a></form>";
echo "</div>";
echo "</td>";
echo "</tr>";
}
}
echo "</tbody></table>\n";
?>
</div>
</div>
</div>
</div>
<?php