From 4872ea487c3d97c670f6bbf34ab99c15363967b0 Mon Sep 17 00:00:00 2001 From: Rasmus Fuhse <krassmus@gmail.com> Date: Fri, 12 Sep 2014 07:01:39 +0200 Subject: [PATCH] Edit releases and add webhook url for github --- PluginMarket.class.php | 9 +++++ classes/MarketRelease.class.php | 4 ++ controllers/myplugins.php | 25 ++++++++++++ controllers/presenting.php | 13 ++++++- controllers/update.php | 3 ++ views/myplugins/_edit_release.php | 65 +++++++++++++++++++++++++++++++ views/myplugins/edit.php | 55 +------------------------- views/myplugins/edit_release.php | 8 ++++ views/presenting/details.php | 8 +++- views/presenting/overview.php | 30 +++++++------- 10 files changed, 149 insertions(+), 71 deletions(-) create mode 100644 views/myplugins/_edit_release.php create mode 100644 views/myplugins/edit_release.php diff --git a/PluginMarket.class.php b/PluginMarket.class.php index b39d88f..ecb7e87 100644 --- a/PluginMarket.class.php +++ b/PluginMarket.class.php @@ -13,6 +13,15 @@ class PluginMarket extends StudIPPlugin implements SystemPlugin { if ($GLOBALS['perm']->have_perm("autor")) { $top->addSubNavigation("myplugins", new Navigation(_("Meine Plugins"), PluginEngine::getURL($this, array(), "myplugins/overview"))); } + if ($GLOBALS['perm']->have_perm("user")) { + $last_visit = object_get_visit(get_class($this), "plugin"); + if ($last_visit !== false) { + $badge_number = MarketPlugin::countBySql("mkdate > ?", array($last_visit)); + if ($badge_number > 0) { + $top->setBadgeNumber($badge_number); + } + } + } Navigation::addItem("/pluginmarket", $top); $loginlink = new Navigation($this->getDisplayTitle(), PluginEngine::getURL($this, array(), "presenting/overview")); diff --git a/classes/MarketRelease.class.php b/classes/MarketRelease.class.php index 1e6e6a9..0c774dc 100644 --- a/classes/MarketRelease.class.php +++ b/classes/MarketRelease.class.php @@ -68,6 +68,10 @@ class MarketRelease extends SimpleORMap { return md5_file($this->getFilePath()); } + public function getSecurityHash() { + return md5($this->getId()."-".$this['mkdate']); + } + protected function installFromDirectory($dir) { $manifest = PluginManager::getInstance()->getPluginManifest($dir); $this['studip_min_version'] = $manifest['studipMinVersion']; diff --git a/controllers/myplugins.php b/controllers/myplugins.php index 62f81b5..e58b6be 100644 --- a/controllers/myplugins.php +++ b/controllers/myplugins.php @@ -32,6 +32,14 @@ class MypluginsController extends PluginController { } } + public function edit_release_action($release_id) { + $this->release = new MarketRelease($release_id); + if (Request::isXhr()) { + $this->response->add_header('X-Title', _("Plugin bearbeiten")); + $this->set_layout(null); + } + } + public function save_action() { if (!Request::isPost()) { throw new Exception("Method not allowed. Try a POST request."); @@ -55,4 +63,21 @@ class MypluginsController extends PluginController { $this->redirect("pluginmarket/presenting/details/".$this->marketplugin->getId()); } + public function save_release_action() { + if (!Request::isPost()) { + throw new Exception("Method not allowed. Try a POST request."); + } + $this->release = new MarketRelease(Request::option("id")); + $release_data = Request::getArray("release"); + $this->release->setData($release_data); + if ($release_data['type'] === "zipfile") { + $this->release['repository_download_url'] = null; + } + $this->release->installFile(); + $this->release->store(); + + PageLayout::postMessage(MessageBox::success(_("Release wurde gespeichert."))); + $this->redirect("pluginmarket/presenting/details/".$this->release->plugin->getId()); + } + } \ No newline at end of file diff --git a/controllers/presenting.php b/controllers/presenting.php index 4d8b4f3..aea04e2 100644 --- a/controllers/presenting.php +++ b/controllers/presenting.php @@ -8,10 +8,21 @@ class PresentingController extends PluginController { parent::before_filter($action, $args); Navigation::activateItem("/pluginmarket/presenting"); + if ($GLOBALS['perm']->have_perm("user")) { + object_set_visit(get_class($this->plugin), "plugin"); + } } public function overview_action() { - $this->plugins = MarketPlugin::findBySQL("1=1"); + + if ($GLOBALS['perm']->have_perm("user")) { + $last_visit = object_get_visit(get_class($this->plugin), "plugin"); + if ($last_visit !== false) { + $this->new_plugins = MarketPlugin::findBySql("mkdate > ? ORDER BY mkdate DESC", array($last_visit)); + } + } + + $this->plugins = MarketPlugin::findBySQL("1=1 ORDER BY name ASC"); } public function details_action($plugin_id) { diff --git a/controllers/update.php b/controllers/update.php index baa8709..8e98dba 100644 --- a/controllers/update.php +++ b/controllers/update.php @@ -13,6 +13,9 @@ class UpdateController extends PluginController { echo "OK"; die(); } + if ($release->getSecurityHash() === Request::get("s")) { + $release->installFile(); + } } } \ No newline at end of file diff --git a/views/myplugins/_edit_release.php b/views/myplugins/_edit_release.php new file mode 100644 index 0000000..b9a0936 --- /dev/null +++ b/views/myplugins/_edit_release.php @@ -0,0 +1,65 @@ +<? +if (strpos($_SERVER['SERVER_NAME'], ':') !== false) { + list($_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']) = + explode(':', $_SERVER['SERVER_NAME']); +} + +$DOMAIN_STUDIP = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'; +$DOMAIN_STUDIP .= '://'.$_SERVER['SERVER_NAME']; + +if ($_SERVER['HTTPS'] == 'on' && $_SERVER['SERVER_PORT'] != 443 || + $_SERVER['HTTPS'] != 'on' && $_SERVER['SERVER_PORT'] != 80) { + $DOMAIN_STUDIP .= ':'.$_SERVER['SERVER_PORT']; +} + +?> + +<fieldset> + <legend> + <?= _("Release hinzuf�gen") ?> + </legend> + + <div> + <label> + <input type="radio" name="release[type]" value="zipfile"<?= !$release['repository_download_url'] ? " checked" : "" ?>> + <?= _("Als Datei") ?> + </label> + <label> + <input type="radio" name="release[type]" value="git"<?= $release['repository_download_url'] ? " checked" : "" ?>> + <?= _("Als Git-Branch") ?> + </label> + </div> + + <fieldset> + <legend> + <?= _("ZIP ausw�hlen") ?> + </legend> + <label> + <a style="cursor: pointer"> + <?= Assets::img("icons/20/blue/upload") ?> + <input type="file" name="release_file"> + </a> + </label> + </fieldset> + + <fieldset> + <legend> + <?= _("Git-Branch") ?> + </legend> + + <label> + <?= _("Download-URL des Branches oder des Tags") ?> + <input type="text" name="release[repository_download_url]" value="<?= htmlReady($release['repository_download_url']) ?>"> + </label> + <p class="info"> + <?= _("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 einzuf�gen. Nach dem Speichern hier k�nnen 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> + <? if (!$release->isNew()) : ?> + <p class="info"> + <?= _("Webhook-URL zum Einf�gen in github oder gitlab:") ?> + <input type="text" style="border: thin solid #cccccc; background-color: #eeeeee;" value="<?= $DOMAIN_STUDIP.URLHelper::getLink("plugins.php/pluginmarket/upate/".$release->getId(), array('s' => $release->getSecurityHash()), true) ?>"> + </p> + <? endif ?> + + </fieldset> +</fieldset> \ No newline at end of file diff --git a/views/myplugins/edit.php b/views/myplugins/edit.php index d37a4c0..d02c3d0 100644 --- a/views/myplugins/edit.php +++ b/views/myplugins/edit.php @@ -37,60 +37,7 @@ </div> </fieldset> - <fieldset> - <legend> - <?= _("Release hinzuf�gen") ?> - </legend> - - <label> - <?= _("Releasebezeichnung") ?> - <input type="text" name="release[version]" placeholder="<?= _("z.B. Rocky Raccoon 3.0.1") ?>"> - </label> - - <div> - <label> - <input type="radio" name="release[type]" value="zipfile"> - <?= _("Als Datei") ?> - </label> - <label> - <input type="radio" name="release[type]" value="git"> - <?= _("Als Git-Branch") ?> - </label> - <label> - <input type="radio" name="release[type]" value=""> - <?= _("Kein Release hinzuf�gen") ?> - </label> - </div> - - <fieldset> - <legend> - <?= _("ZIP ausw�hlen") ?> - </legend> - <label> - <a style="cursor: pointer"> - <?= Assets::img("icons/20/blue/upload") ?> - <input type="file" name="release_file"> - </a> - </label> - </fieldset> - - <fieldset> - <legend> - <?= _("Git-Branch") ?> - </legend> - - <label> - <?= _("Download-URL des Branches oder des Tags") ?> - <input type="text" name="release[repository_download_url]"> - </label> - <p class="info"> - <?= _("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 einzuf�gen. Nach dem Speichern hier k�nnen 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> - - </fieldset> - </fieldset> - - + <?= $this->render_partial("myplugins/_edit_release.php", array('release' => new MarketRelease())) ?> <div data-dialog-button> <?= \Studip\Button::create(_("speichern")) ?> diff --git a/views/myplugins/edit_release.php b/views/myplugins/edit_release.php new file mode 100644 index 0000000..5fcae4a --- /dev/null +++ b/views/myplugins/edit_release.php @@ -0,0 +1,8 @@ +<form action="<?= PluginEngine::getLink($plugin, array(), "myplugins/save_release") ?>" method="post" class="studip_form" enctype="multipart/form-data"> + <input type="hidden" name="id" value="<?= $release->getId() ?>"> + <?= $this->render_partial("myplugins/_edit_release.php", array('release' => $release)) ?> + + <div data-dialog-button> + <?= \Studip\Button::create(_("speichern")) ?> + </div> +</form> \ No newline at end of file diff --git a/views/presenting/details.php b/views/presenting/details.php index b09b9c4..5a7bc46 100644 --- a/views/presenting/details.php +++ b/views/presenting/details.php @@ -29,7 +29,11 @@ <td><?= htmlReady($release->getChecksum()) ?></td> <td><?= htmlReady($release['downloads']) ?></td> <td> - + <? if ($marketplugin['user_id'] === $GLOBALS['user']->id) : ?> + <a href="<?= PluginEngine::getLink($plugin, array(), "myplugins/edit_release/".$release->getId()) ?>" data-dialog> + <?= Assets::img("icons/20/blue/edit", array('class' => "text-bottom")) ?> + </a> + <? endif ?> </td> </tr> <? endforeach ?> @@ -37,5 +41,5 @@ </table> <div style="text-align: center"> - <?= \Studip\LinkButton::create(_("bearbeiten"), PluginEngine::getURL($plugin, array(), "myplugins/edit/".$marketplugin->getId())) ?> + <?= \Studip\LinkButton::create(_("bearbeiten"), PluginEngine::getURL($plugin, array(), "myplugins/edit/".$marketplugin->getId()), array('data-dialog' => 1)) ?> </div> \ No newline at end of file diff --git a/views/presenting/overview.php b/views/presenting/overview.php index 8eb1da3..c3cdae9 100644 --- a/views/presenting/overview.php +++ b/views/presenting/overview.php @@ -42,21 +42,23 @@ } </style> +<? if (isset($new_plugins) && count($new_plugins)) : ?> + <h2><?= _("Neue Plugins seit Ihrem letzten Besuch") ?></h2> + <div class="plugins_shortview"> + <? foreach ($new_plugins as $marketplugin) : ?> + <article> + <h1><a href="<?= PluginEngine::getLink($plugin, array(), "presenting/details/".$marketplugin->getId()) ?>"><?= htmlReady($marketplugin['name']) ?></a></h1> + <div class="image" style="background-image: url(http://plugins.studip.de/content/screenshots/a1d85f695cfe506241d398d272ae43f0_thumb);"></div> + <p class="shortdescription"> + <?= htmlReady($marketplugin['short_description']) ?> + </p> + </article> + <? endforeach ?> + </div> +<? endif ?> + + <div class="plugins_shortview"> - <article> - <h1><a href="">BlubberMail</a></h1> - <div class="image" style="background-image: url(http://plugins.studip.de/content/screenshots/a1d85f695cfe506241d398d272ae43f0_thumb);"></div> - <p class="shortdescription"> - Blubbern �ber Email. Man bekommt Mails, wenn die Diskussion weiter geht, man kann per Mail darauf antworten und man kann Blubberstreams per Mail abonnieren. - </p> - </article> - <article> - <h1>ArchivierungsPlugin</h1> - <div class="image" style="background-image: url(http://plugins.studip.de/content/screenshots/5c6b989378b09deb4b5a79b32a0aa0bc);"></div> - <p class="shortdescription"> - Zentrale Archivierung/L�schung von Veranstaltungen durch Admins. Die Veranstaltungen k�nnen nach verschiedenen Kriterien eingeschr�nkt werden. - </p> - </article> <? foreach ($plugins as $marketplugin) : ?> <article> <h1><a href="<?= PluginEngine::getLink($plugin, array(), "presenting/details/".$marketplugin->getId()) ?>"><?= htmlReady($marketplugin['name']) ?></a></h1> -- GitLab