Skip to content
Snippets Groups Projects
Commit 2c2b1067 authored by noackorama's avatar noackorama
Browse files

fixes #72

parent 9bbb9a74
No related branches found
No related tags found
No related merge requests found
......@@ -170,4 +170,5 @@ class MarketPlugin extends SimpleORMap {
return $rating;
}
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ class MarketRelease extends SimpleORMap {
public function delete() {
parent::delete();
unlink($this->getFilePath());
@unlink($this->getFilePath());
}
public function installFile() {
......@@ -56,7 +56,13 @@ class MarketRelease extends SimpleORMap {
} else {
$plugin_dir = $tmp_folder;
}
try {
$this->installFromDirectory($plugin_dir, $file);
} catch (PluginInstallationException $e) {
rmdirr($tmp_folder);
unlink($file);
throw $e;
}
rmdirr($tmp_folder);
unlink($file);
......@@ -80,7 +86,7 @@ class MarketRelease extends SimpleORMap {
header('Content-Type: ' . $this->getMimeType());
header('Content-Disposition: attachment; filename="' . $this->getFilename() . '"');
readfile($this->getFilePath());
@readfile($this->getFilePath());
}
public function getMimeType()
......@@ -90,7 +96,7 @@ class MarketRelease extends SimpleORMap {
public function getFilename()
{
return $this->plugin['name'] . '.zip';
return $this->plugin['pluginname'] . '.zip';
}
public function getContentLength()
......@@ -113,9 +119,26 @@ class MarketRelease extends SimpleORMap {
protected function installFromDirectory($dir, $originalfile = null) {
$manifest = PluginManager::getInstance()->getPluginManifest($dir);
if ($manifest['pluginclassname']) {
$this->plugin['pluginclassname'] = $manifest['pluginclassname'];
if ($manifest['pluginname']) {
if ($this->plugin->isNew()) {
$this->plugin['pluginname'] = $manifest['pluginname'];
$this->plugin['name'] = @$manifest['displayname'] ?: $manifest['pluginname'];
$this->plugin['short_description'] = @$manifest['description'] ?: '';
$this->plugin['description'] = @$manifest['descriptionlong'] ?: '';
if (!$this->plugin['description']) {
$this['repository_overwrites_descriptionfrom'] = 1;
}
if (MarketPlugin::findOneByPluginname($this->plugin->pluginname)) {
throw new PluginInstallationException(_("Ein Plugin mit diesem Namen ist schon im Marktplatz vorhanden!"));
}
$this->plugin->store();
} else {
if ($this->plugin['pluginname'] != $manifest['pluginname']) {
throw new PluginInstallationException(sprintf(_("Release hat falschen Pluginnamen, erwartet:%s gefunden:%s"), $this->plugin['pluginname'], $manifest['pluginname']));
}
}
} else {
throw new PluginInstallationException(_("Im Manifest fehlt der Pluginname"));
}
$this['studip_min_version'] = $manifest['studipMinVersion'];
$this['studip_max_version'] = $manifest['studipMaxVersion'];
......@@ -198,4 +221,18 @@ class MarketRelease extends SimpleORMap {
return implode("\n", $arr);
}
public function getPluginName()
{
$zip = new ZipArchive();
if ($zip->open($this->getFilePath())) {
$manifest = $zip->getFromIndex($zip->locateName('plugin.manifest', ZipArchive::FL_NOCASE|ZipArchive::FL_NODIR));
foreach (array_map('trim',explode("\n", $manifest)) as $line) {
list($key, $value) = explode('=', $line);
if ($key === 'pluginname') {
return trim($value);
}
}
}
}
}
\ No newline at end of file
......@@ -20,7 +20,8 @@ class ExternController extends MarketController
$plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 ORDER BY name ASC");
foreach ($plugins as $plugin) {
$xml_plugin = $xml_plugins->appendChild($this->create_xml_element($doc, 'plugin', null, array(
'name' => $plugin->name,
'displayname' => $plugin->name,
'name' => $plugin->pluginname,
'homepage' => $plugin->url,
'short_description' => $plugin->short_description,
'description' => $plugin->description,
......
......@@ -16,11 +16,28 @@ class MypluginsController extends MarketController
$this->plugins = MarketPlugin::findBySQL("user_id = ? ORDER BY mkdate DESC", array($GLOBALS['user']->id));
}
public function addfromzip_action()
{
CSRFProtection::verifyUnsafeRequest();
if (isset($_FILES['release_file']['tmp_name'])) {
$plugin = new MarketPlugin();
$plugin->setId($plugin->getNewId());
$plugin->user_id = $GLOBALS['user']->id;
$release = new MarketRelease();
$release->plugin = $plugin;
$release['user_id'] = $GLOBALS['user']->id;
//throws Exception on error
$release->installFile();
$this->redirect($this->url_for('/overview', ['edit_plugin_id' => $plugin->id]));
}
}
public function add_action() {
$this->marketplugin = new MarketPlugin();
if (Request::isXhr()) {
$this->set_layout(null);
}
$this->render_action("edit");
}
......@@ -80,6 +97,10 @@ class MypluginsController extends MarketController
$data['donationsaccepted'] = 0;
}
$this->marketplugin->setData($data);
if ($this->marketplugin->isNew() && (MarketPlugin::findOneByPluginname($this->marketplugin->pluginname) || !strlen(trim($this->marketplugin->pluginname)))) {
PageLayout::postError(_("Ein Plugin mit diesem Namen ist schon im Marktplatz vorhanden!"));
return $this->redirect($this->url_for('/overview'));
}
if ($this->marketplugin->isNew()) {
$this->marketplugin['user_id'] = $GLOBALS['user']->id;
}
......@@ -129,9 +150,15 @@ class MypluginsController extends MarketController
$release->setData($release_data);
$release['plugin_id'] = $this->marketplugin->getId();
$release['user_id'] = $GLOBALS['user']->id;
try {
$release->installFile();
$release->store();
} catch (PluginInstallationException $e) {
PageLayout::postError($e->getMessage());
return $this->redirect($this->url_for('/overview'));
}
}
}
PageLayout::postMessage(MessageBox::success(_("Plugin wurde gespeichert.")));
$this->redirect('presenting/details/' . $this->marketplugin->getId());
......
......@@ -115,6 +115,7 @@ class PresentingController extends MarketController
$this->plugins = MarketPlugin::findBySQL("
(
name LIKE :likesearch
OR pluginname LIKE :likesearch
OR (SELECT CONCAT(Vorname, ' ', Nachname) FROM auth_user_md5 WHERE user_id = pluginmarket_plugins.user_id LIMIT 1) LIKE :likesearch
OR MATCH (short_description, description) AGAINST (:search IN BOOLEAN MODE)
OR (SELECT GROUP_CONCAT(' ', tag) FROM pluginmarket_tags WHERE pluginmarket_tags.plugin_id = plugin_id GROUP BY pluginmarket_tags.plugin_id LIMIT 1) LIKE :likesearch
......
<?php
class AddPluginname extends Migration {
public function up() {
DBManager::get()->exec("
ALTER TABLE `pluginmarket_plugins` CHANGE `pluginclassname` `pluginname` VARCHAR(64) NOT NULL
");
SimpleORMap::expireTableScheme();
foreach (MarketPlugin::findBySQL("1") as $plugin) {
if ($plugin->releases->count()) {
$pluginnames = array_count_values(array_filter($plugin->releases->getPluginName()));
arsort($pluginnames);
$pluginname = key($pluginnames);
if ($pluginname) {
$plugin->pluginname = $pluginname;
$plugin->releases->each(function ($one) use ($pluginname) {
if ($one->getPluginName() != $pluginname) {
$one->delete();
}
});
} else {
$plugin->name .= " (no pluginname)";
$plugin->releases->delete();
$plugin->approved = 0;
}
} else {
$plugin->name .= " (no release)";
$plugin->approved = 0;
}
$plugin->store();
}
}
public function down() {
}
}
\ No newline at end of file
pluginname=PluginMarktplatz
pluginclassname=PluginMarket
origin=studip
version=1.0.15
version=1.0.16
......@@ -5,10 +5,13 @@
<?= _("Informationen") ?>
</legend>
<label>
<?= _("Name des Plugins") ?>
<input type="text" name="data[name]" value="<?= htmlReady($marketplugin['name']) ?>">
<?= _("Angezeigter Name des Plugins") ?>
<input required type="text" name="data[name]" value="<?= htmlReady($marketplugin['name']) ?>">
</label>
<label>
<?= _("Interner Name des Plugins (aus dem Manifest)") ?>
<input required type="text" name="data[pluginname]" value="<?= htmlReady($marketplugin['pluginname']) ?>" <?=!$marketplugin->isNew() ? 'disabled' : ''?>>
</label>
<label>
<?= _("Kurzbeschreibung") ?>
<input type="text" name="data[short_description]" value="<?= htmlReady($marketplugin['short_description']) ?>" maxlength="160">
......@@ -25,7 +28,7 @@
<label>
<?= _("Lange Beschreibung") ?>
<textarea class="add_toolbar" name="data[description]"><?= htmlReady($marketplugin['description']) ?></textarea>
<textarea class="wysiwyg" name="data[description]"><?= htmlReady($marketplugin['description']) ?></textarea>
</label>
<label>
......
......@@ -66,7 +66,13 @@
</tbody>
</table>
<? if ($edit_plugin_id = Request::option('edit_plugin_id')): ?>
<script>
jQuery(function ($) {
STUDIP.Dialog.fromURL('<?= $controller->url_for('myplugins/edit/' . $edit_plugin_id) ?>');
});
</script>
<? endif; ?>
<?
$sidebar = Sidebar::Get();
$sidebar->setImage(Assets::image_path("sidebar/plugin-sidebar.png"));
......@@ -74,5 +80,14 @@ $actions = new ActionsWidget();
$actions->addLink(_("Neues Plugin eintragen"),
$controller->url_for('myplugins/add'),
Icon::create('add'))->asDialog();
$actions->addElement(new WidgetElement(
'<form action="' . $controller->url_for('myplugins/addfromzip') .'"
method="post" enctype="multipart/form-data" class="drag-and-drop">
<input type="hidden" name="release[type]" value="zipfile">
'. CSRFProtection::tokenTag() .'
'._('Plugin via Drag and Drop eintragen') .'
<input type="file" name="release_file">
</form>'
));
$sidebar->addWidget($actions);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment