Skip to content
Snippets Groups Projects
Commit fb4a6a57 authored by Rasmus Fuhse's avatar Rasmus Fuhse
Browse files

more works

parent f49ad882
No related branches found
No related tags found
No related merge requests found
<?php <?php
require_once __DIR__."/classes/MarketPlugin.class.php"; require_once __DIR__."/classes/MarketPlugin.class.php";
require_once __DIR__."/classes/MarketRelease.class.php";
class PluginMarket extends StudIPPlugin implements SystemPlugin { class PluginMarket extends StudIPPlugin implements SystemPlugin {
......
<?php <?php
require_once 'lib/datei.inc.php';
class MarketRelease extends SimpleORMap { class MarketRelease extends SimpleORMap {
static public function getReleaseDataPath() {
return $GLOBALS['STUDIP_BASE_PATH'] . "/data/pluginmarket_releases";
}
protected static function configure($config = array()) protected static function configure($config = array())
{ {
$config['db_table'] = 'pluginmarket_releases'; $config['db_table'] = 'pluginmarket_releases';
...@@ -11,4 +17,58 @@ class MarketRelease extends SimpleORMap { ...@@ -11,4 +17,58 @@ class MarketRelease extends SimpleORMap {
); );
parent::configure($config); parent::configure($config);
} }
public function installFile() {
$hash = md5(uniqid());
$tmp_folder = $GLOBALS['TMP_PATH']."/temp_plugin_".$hash;
mkdir($tmp_folder);
$file = $GLOBALS['TMP_PATH']."/temp_plugin_".$hash.".zip";
if ($this['repository_download_url']) {
file_put_contents($file, file_get_contents($this['repository_download_url']));
} elseif ($_FILES['release_file']['tmp_name']) {
move_uploaded_file($_FILES['release_file']['tmp_name'], $file);
} else {
return false;
}
unzip_file($file, $tmp_folder);
$objects = scandir($tmp_folder);
if (count($objects) === 3) {
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
$plugin_dir = $tmp_folder."/".$object;
}
}
} else {
$plugin_dir = $tmp_folder;
}
$this->installFromDirectory($plugin_dir);
rmdirr($tmp_folder);
unlink($file);
}
protected function installFromDirectory($dir) {
$manifest = PluginManager::getInstance()->getPluginManifest($dir);
$this['studip_min_version'] = $manifest['studipMinVersion'];
$this['studip_max_version'] = $manifest['studipMaxVersion'];
if (!$this['version']) {
$this['version'] = $manifest['version'];
}
$hash = md5(uniqid());
$plugin = $GLOBALS['TMP_PATH']."/plugin_$hash.zip";
create_zip_from_directory($dir, $plugin);
$RELEASE_DATA_PATH = self::getReleaseDataPath();
if (!file_exists($RELEASE_DATA_PATH)) {
mkdir($RELEASE_DATA_PATH);
}
if (!$this->getId()) {
$this->setId($this->getNewId());
}
copy($plugin, $RELEASE_DATA_PATH."/".$this->getId());
unlink($plugin);
return true;
}
} }
\ No newline at end of file
...@@ -26,6 +26,10 @@ class MypluginsController extends PluginController { ...@@ -26,6 +26,10 @@ class MypluginsController extends PluginController {
public function edit_action($plugin_id) { public function edit_action($plugin_id) {
$this->marketplugin = new MarketPlugin($plugin_id); $this->marketplugin = new MarketPlugin($plugin_id);
if (Request::isXhr()) {
$this->response->add_header('X-Title', _("Plugin bearbeiten"));
$this->set_layout(null);
}
} }
public function save_action() { public function save_action() {
...@@ -38,6 +42,15 @@ class MypluginsController extends PluginController { ...@@ -38,6 +42,15 @@ class MypluginsController extends PluginController {
$this->marketplugin['user_id'] = $GLOBALS['user']->id; $this->marketplugin['user_id'] = $GLOBALS['user']->id;
} }
$this->marketplugin->store(); $this->marketplugin->store();
$release_data = Request::getArray("release");
if ($release_data['type']) {
$release = new MarketRelease();
$release->setData($release_data);
$release['plugin_id'] = $this->marketplugin->getId();
$release['user_id'] = $GLOBALS['user']->id;
$release->installFile();
$release->store();
}
PageLayout::postMessage(MessageBox::success(_("Plugin wurde gespeichert."))); PageLayout::postMessage(MessageBox::success(_("Plugin wurde gespeichert.")));
$this->redirect("pluginmarket/presenting/details/".$this->marketplugin->getId()); $this->redirect("pluginmarket/presenting/details/".$this->marketplugin->getId());
} }
......
<?php
require_once 'app/controllers/plugin_controller.php';
class UpdateController extends PluginController {
public function release_action($release_id) {
$release = new MarketRelease($release_id);
if ($release->isNew()) {
throw new Exception("Unknown release.");
}
if (!$release['repository_download_url']) {
//might happen more often than we think, so we better be polite and die.
echo "OK";
die();
}
}
}
\ No newline at end of file
...@@ -27,7 +27,8 @@ CREATE TABLE IF NOT EXISTS `pluginmarket_releases` ( ...@@ -27,7 +27,8 @@ CREATE TABLE IF NOT EXISTS `pluginmarket_releases` (
`file_id` varchar(32) default NULL, `file_id` varchar(32) default NULL,
`downloads` int(20) NOT NULL default '0', `downloads` int(20) NOT NULL default '0',
`release_type` varchar(255) default NULL, `release_type` varchar(255) default NULL,
`origin` varchar(255) NOT NULL, `origin` varchar(255) NULL,
`repository_download_url` VARCHAR( 128 ) NULL,
`chdate` int(20) NOT NULL, `chdate` int(20) NOT NULL,
`mkdate` int(20) NOT NULL, `mkdate` int(20) NOT NULL,
PRIMARY KEY (`release_id`), PRIMARY KEY (`release_id`),
......
<form action="<?= PluginEngine::getLink($plugin, array(), "myplugins/save") ?>" method="post" class="studip_form"> <form action="<?= PluginEngine::getLink($plugin, array(), "myplugins/save") ?>" method="post" class="studip_form" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?= $marketplugin->getId() ?>"> <input type="hidden" name="id" value="<?= $marketplugin->getId() ?>">
<fieldset> <fieldset>
<legend> <legend>
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
<label> <label>
<?= _("Releasebezeichnung") ?> <?= _("Releasebezeichnung") ?>
<input type="text" name="release[name]" placeholder="<?= _("z.B. Rocky Raccoon 3.0.1") ?>"> <input type="text" name="release[version]" placeholder="<?= _("z.B. Rocky Raccoon 3.0.1") ?>">
</label> </label>
<div> <div>
...@@ -56,6 +56,10 @@ ...@@ -56,6 +56,10 @@
<input type="radio" name="release[type]" value="git"> <input type="radio" name="release[type]" value="git">
<?= _("Als Git-Branch") ?> <?= _("Als Git-Branch") ?>
</label> </label>
<label>
<input type="radio" name="release[type]" value="">
<?= _("Kein Release hinzufgen") ?>
</label>
</div> </div>
<fieldset> <fieldset>
...@@ -65,7 +69,7 @@ ...@@ -65,7 +69,7 @@
<label> <label>
<a style="cursor: pointer"> <a style="cursor: pointer">
<?= Assets::img("icons/20/blue/upload") ?> <?= Assets::img("icons/20/blue/upload") ?>
<input type="file" name="release[file]"> <input type="file" name="release_file">
</a> </a>
</label> </label>
</fieldset> </fieldset>
...@@ -77,10 +81,10 @@ ...@@ -77,10 +81,10 @@
<label> <label>
<?= _("Download-URL des Branches oder des Tags") ?> <?= _("Download-URL des Branches oder des Tags") ?>
<input type="release[git_download]"> <input type="text" name="release[repository_download_url]">
</label> </label>
<p class="info"> <p class="info">
<?= _("Github und gitlab bieten zu jedem Branch und Tag den Download als ZIP-Datei an. Klicken Sie dort mit rechter Maustaste auf den Downloadbutton und kopieren Sie die URL, um sie hier einzufgen. Nach dem Speichern hier knnen Sie auf github bzw. gitlab Webhooks einrichten, damit der Marktplatz sich automatisch die neuste Version des Plugins vom Repository holt.") ?> <?= _("Github.com und gitlab bieten zu jedem Branch und Tag den Download als ZIP-Datei an. Klicken Sie dort mit rechter Maustaste auf den Downloadbutton und kopieren Sie die URL, um sie hier einzufgen. Nach dem Speichern hier knnen Sie auf github bzw. gitlab Webhooks einrichten, damit der Marktplatz sich automatisch die neuste Version des Plugins vom Repository holt. Damit ist das Plugin auf dem Pluginmarktplatz immer brandaktuell.") ?>
</p> </p>
</fieldset> </fieldset>
......
<? foreach ($plugins as $plugin) : ?> <table class="default">
<? endforeach ?> <thead>
<tr>
<th><?= _("Name") ?></th>
<th></th>
</tr>
</thead>
<tbody>
<? foreach ($plugins as $marketplugin) : ?>
<tr>
<td><?= htmlReady($marketplugin['name']) ?></td>
<td>
<a href="<?= PluginEngine::getLink($plugin, array(), "myplugins/edit/".$marketplugin->getId()) ?>" data-dialog><?= Assets::img("icons/20/blue/edit") ?></a>
</td>
</tr>
<? endforeach ?>
</tbody>
</table>
<? <?
$sidebar = Sidebar::Get(); $sidebar = Sidebar::Get();
......
<h1><?= htmlReady($marketplugin['name']) ?></h1> <h1><?= htmlReady($marketplugin['name']) ?></h1>
<div> <div>
<?= formatReady($marketplugin['description']) ?> <?= formatReady($marketplugin['description']) ?>
</div>
<h2><?= _("Releases") ?></h2>
<table class="default">
<thead>
<tr>
<th><?= _("Version") ?></th>
<th><?= _("Miniale Stud.IP-Versionsnummer") ?></th>
<th><?= _("Maximale Stud.IP-Versionsnummer") ?></th>
</tr>
</thead>
<tbody>
<? foreach ($marketplugin->releases as $release) : ?>
<tr>
<td><?= htmlReady($release['version']) ?></td>
<td><?= $release['studip_min_version'] ? htmlReady($release['studip_min_version']) : " - " ?></td>
<td><?= $release['studip_max_version'] ? htmlReady($release['studip_max_version']) : " - " ?></td>
</tr>
<? endforeach ?>
</tbody>
</table>
<div style="text-align: center">
<?= \Studip\LinkButton::create(_("bearbeiten"), PluginEngine::getURL($plugin, array(), "myplugins/edit/".$marketplugin->getId())) ?>
</div> </div>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment