Skip to content
Snippets Groups Projects
Commit a44d6f06 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

implement absolute_url_for() on MarketController for generic use, re #9

parent f511742b
No related branches found
No related tags found
No related merge requests found
<?php <?php
class MarketImage extends SimpleORMap { class MarketImage extends SimpleORMap
{
static public function findByPlugin_id($plugin_id) { static public function findByPlugin_id($plugin_id) {
return self::findBySQL("plugin_id = ? ORDER BY position ASC, mkdate ASC", array($plugin_id)); return self::findBySQL("plugin_id = ? ORDER BY position ASC, mkdate ASC", array($plugin_id));
} }
...@@ -20,8 +20,19 @@ class MarketImage extends SimpleORMap { ...@@ -20,8 +20,19 @@ class MarketImage extends SimpleORMap {
parent::configure($config); parent::configure($config);
} }
public function getURL() { public function getURL($absolute_url = false)
return URLHelper::getURL("plugins.php/pluginmarket/presenting/image/".$this->getId(), array(), true); {
if ($absolute_url) {
$old_base = URLHelper::setBaseURL($GLOBALS['ABSOLUTE_URI_STUDIP']);
}
$url = URLHelper::getURL("plugins.php/pluginmarket/presenting/image/".$this->getId(), array(), true);
if ($absolute_url) {
URLHelper::setBaseURL($old_base);
}
return $url;
} }
public function delete() { public function delete() {
......
...@@ -66,9 +66,10 @@ class MarketPlugin extends SimpleORMap { ...@@ -66,9 +66,10 @@ class MarketPlugin extends SimpleORMap {
return $GLOBALS['perm']->have_perm("root", $user_id); return $GLOBALS['perm']->have_perm("root", $user_id);
} }
public function getLogoURL() { public function getLogoURL($absolute_url = false)
{
$firstimage = $this->images->first(); $firstimage = $this->images->first();
return $firstimage ? $firstimage->getURL() : Assets::image_path("icons/blue/plugin.svg"); return $firstimage ? $firstimage->getURL($absolute_url) : Assets::image_path("icons/blue/plugin.svg");
} }
public function setTags($tags) { public function setTags($tags) {
......
<?php <?php
require_once 'app/controllers/plugin_controller.php'; require_once 'market_controller.php';
class ApprovingController extends PluginController { class ApprovingController extends MarketController
{
function before_filter(&$action, &$args) function before_filter(&$action, &$args)
{ {
......
<?php <?php
require_once 'app/controllers/plugin_controller.php'; require_once 'market_controller.php';
class ExternController extends PluginController class ExternController extends MarketController
{ {
public function xml_action() { public function before_filter(&$action, &$args)
$this->plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 ORDER BY name ASC"); {
URLHelper::setBaseUrl($GLOBALS['ABSOLUTE_URI_STUDIP']); parent::before_filter($action, $args);
$this->set_layout(null); $this->set_layout(null);
}
public function xml_action()
{
$this->plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 ORDER BY name ASC");
$this->response->add_header('Content-Type', "text/xml"); $this->response->add_header('Content-Type', "text/xml");
} }
public function find_releases_action() { public function find_releases_action()
{
$output = array(); $output = array();
$studipversion = Request::get("studipversion"); $studipversion = Request::get("studipversion");
$plugins = MarketPlugin::findByPluginclassname(Request::get("classname")); $plugins = MarketPlugin::findByPluginclassname(Request::get("classname"));
...@@ -22,9 +29,9 @@ class ExternController extends PluginController ...@@ -22,9 +29,9 @@ class ExternController extends PluginController
if ((!$release['studip_min_version'] || version_compare($studipversion, $release['studip_min_version'], ">=")) if ((!$release['studip_min_version'] || version_compare($studipversion, $release['studip_min_version'], ">="))
&& (!$release['studip_max_version'] || version_compare($studipversion, $release['studip_max_version'], "<="))) { && (!$release['studip_max_version'] || version_compare($studipversion, $release['studip_max_version'], "<="))) {
$output['releases'][] = array( $output['releases'][] = array(
'version' => $release['version'], 'version' => $release['version'],
'html_url' => PluginEngine::getURL($this->plugin, array(), "presenting/details/".$plugin->getId()), 'html_url' => $this->url_for('presenting/details/' . $plugin->getId()),
'download_url' => PluginEngine::getURL($this->plugin, array(), "presenting/download/".$release->getId()) 'download_url' => $this->url_for('presenting/download/' . $release->getId()),
); );
} }
} }
......
<?php
require_once 'app/controllers/plugin_controller.php';
class MarketController extends PluginController
{
public function absolute_url_for($to)
{
$old_base = URLHelper::setBaseURL($GLOBALS['ABSOLUTE_URI_STUDIP']);
$args = func_get_args();
$url = call_user_func_array(array($this, 'url_for'), $args);
URLHelper::setBaseURL($old_base);
return $url;
}
}
<?php <?php
require_once 'app/controllers/plugin_controller.php'; require_once 'market_controller.php';
class MypluginsController extends PluginController {
class MypluginsController extends MarketController
{
function before_filter(&$action, &$args) function before_filter(&$action, &$args)
{ {
parent::before_filter($action, $args); parent::before_filter($action, $args);
......
<?php <?php
require_once 'app/controllers/plugin_controller.php'; require_once 'market_controller.php';
class PresentingController extends PluginController {
class PresentingController extends MarketController
{
protected $last_pluginmarket_visit = null; protected $last_pluginmarket_visit = null;
function before_filter(&$action, &$args) function before_filter(&$action, &$args)
......
<?php <?php
require_once 'app/controllers/plugin_controller.php'; require_once 'market_controller.php';
class UpdateController extends PluginController { class UpdateController extends MarketController
{
public function release_action($release_id) { public function release_action($release_id)
{
$release = new MarketRelease($release_id); $release = new MarketRelease($release_id);
if ($release->isNew()) { if ($release->isNew()) {
throw new Exception("Unknown release."); throw new Exception("Unknown release.");
...@@ -20,5 +21,4 @@ class UpdateController extends PluginController { ...@@ -20,5 +21,4 @@ class UpdateController extends PluginController {
$this->render_text("Insecure request."); $this->render_text("Insecure request.");
} }
} }
} }
\ No newline at end of file
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
homepage="<?= htmlReady(studip_utf8encode($marketplugin['url'])) ?>" homepage="<?= htmlReady(studip_utf8encode($marketplugin['url'])) ?>"
short_description="<?= htmlReady(studip_utf8encode($marketplugin['short_description'])) ?>" short_description="<?= htmlReady(studip_utf8encode($marketplugin['short_description'])) ?>"
description="<?= htmlReady(studip_utf8encode($marketplugin['description'])) ?>" description="<?= htmlReady(studip_utf8encode($marketplugin['description'])) ?>"
image="<?= htmlReady(studip_utf8encode($marketplugin->getLogoURL())) ?>"> image="<?= htmlReady(studip_utf8encode($marketplugin->getLogoURL(true))) ?>">
<? foreach ($marketplugin->releases as $release) : ?> <? foreach ($marketplugin->releases as $release) : ?>
<release <release
version="<?= htmlReady(studip_utf8encode($release['version'])) ?>" version="<?= htmlReady(studip_utf8encode($release['version'])) ?>"
studipMinVersion="<?= htmlReady(studip_utf8encode($release['studip_min_version'])) ?>" studipMinVersion="<?= htmlReady(studip_utf8encode($release['studip_min_version'])) ?>"
studipMaxVersion="<?= htmlReady(studip_utf8encode($release['studip_min_version'])) ?>" studipMaxVersion="<?= htmlReady(studip_utf8encode($release['studip_min_version'])) ?>"
url="<?= htmlReady(studip_utf8encode($controller->url_for('presenting/download/' . $release->getId()))) ?>" url="<?= htmlReady(studip_utf8encode($controller->absolute_url_for('presenting/download/' . $release->getId()))) ?>"
/> />
<? endforeach ?> <? endforeach ?>
</plugin> </plugin>
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<? if (!$release->isNew()) : ?> <? if (!$release->isNew()) : ?>
<p class="info"> <p class="info">
<?= _("Webhook-URL zum Einfgen in github oder gitlab:") ?> <?= _("Webhook-URL zum Einfgen in github oder gitlab:") ?>
<input type="text" readonly style="border: thin solid #cccccc; background-color: #eeeeee; width:100%;" value="<?= $GLOBALS['ABSOLUTE_URI_STUDIP']."plugins.php/pluginmarket/update/release/".$release->getId().'?s='.$release->getSecurityHash() ?>"> <input type="text" readonly style="border: thin solid #cccccc; background-color: #eeeeee; width:100%;" value="<?= $controller->absolute_url_for('update/release/' . $release->getId(), array('s' => $release->getSecurityHash())) ?>">
</p> </p>
<? if ($domain_warning) : ?> <? if ($domain_warning) : ?>
<p class="info"><?= htmlReady($domain_warning) ?></p> <p class="info"><?= htmlReady($domain_warning) ?></p>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<legend><?= _("Konfigurieren Sie Ihr Stud.IP") ?></legend> <legend><?= _("Konfigurieren Sie Ihr Stud.IP") ?></legend>
<label> <label>
<?= _("Download-URL - geben Sie diese URL in Ihrem Stud.IP in der Pluginverwaltung ein") ?> <?= _("Download-URL - geben Sie diese URL in Ihrem Stud.IP in der Pluginverwaltung ein") ?>
<input type="text" readonly value="<?= $GLOBALS['ABSOLUTE_URI_STUDIP'] . $controller->url_for('presenting/download/' . $release->getId()) ?>"> <input type="text" readonly value="<?= $controller->absolute_url_for('presenting/download/' . $release->getId()) ?>">
</label> </label>
</fieldset> </fieldset>
<fieldset> <fieldset>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment