Fix the rest of the menu urls
This commit is contained in:
parent
779f4a00eb
commit
4ef2d6df57
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<title><?= $title ?></title>
|
<title><?= $title ?></title>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="stylesheet" href="<?= $escape->attr($urlGenerator->asset_url('css.php?g=base')) ?>" />
|
<link rel="stylesheet" href="<?= $urlGenerator->asset_url('css.php?g=base') ?>" />
|
||||||
<script>
|
<script>
|
||||||
var BASE_URL = "<?= $urlGenerator->base_url($url_type) ?>";
|
var BASE_URL = "<?= $urlGenerator->base_url($url_type) ?>";
|
||||||
var CONTROLLER = "<?= $url_type ?>";
|
var CONTROLLER = "<?= $url_type ?>";
|
||||||
@ -28,7 +28,7 @@
|
|||||||
<?= $helper->menu($menu_name) ?>
|
<?= $helper->menu($menu_name) ?>
|
||||||
<?php if (is_view_page()): ?>
|
<?php if (is_view_page()): ?>
|
||||||
<br />
|
<br />
|
||||||
<ul class="align_right">
|
<ul>
|
||||||
<li class="<?= is_not_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url($route_path) ?>">Cover View</a></li>
|
<li class="<?= is_not_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url($route_path) ?>">Cover View</a></li>
|
||||||
<li class="<?= is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li>
|
<li class="<?= is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -4,11 +4,29 @@
|
|||||||
*/
|
*/
|
||||||
namespace Aviat\AnimeClient;
|
namespace Aviat\AnimeClient;
|
||||||
|
|
||||||
|
use Aviat\Ion\Di\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UrlGenerator class.
|
* UrlGenerator class.
|
||||||
*/
|
*/
|
||||||
class UrlGenerator extends RoutingBase {
|
class UrlGenerator extends RoutingBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current HTTP host
|
||||||
|
*/
|
||||||
|
protected $host;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param ContainerInterface $container
|
||||||
|
*/
|
||||||
|
public function __construct(ContainerInterface $container)
|
||||||
|
{
|
||||||
|
parent::__construct($container);
|
||||||
|
$this->host = $container->get('request')->server->get('HTTP_HOST');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the base url for css/js/images
|
* Get the base url for css/js/images
|
||||||
*
|
*
|
||||||
@ -36,11 +54,9 @@ class UrlGenerator extends RoutingBase {
|
|||||||
{
|
{
|
||||||
$config_path = trim($this->__get("{$type}_path"), "/");
|
$config_path = trim($this->__get("{$type}_path"), "/");
|
||||||
|
|
||||||
// Set the appropriate HTTP host
|
|
||||||
$host = $_SERVER['HTTP_HOST'];
|
|
||||||
$path = ($config_path !== '') ? $config_path : "";
|
$path = ($config_path !== '') ? $config_path : "";
|
||||||
|
|
||||||
return implode("/", ['/', $host, $path]);
|
return implode("/", ['/', $this->host, $path]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,13 +69,25 @@ class UrlGenerator extends RoutingBase {
|
|||||||
{
|
{
|
||||||
$path = trim($path, '/');
|
$path = trim($path, '/');
|
||||||
|
|
||||||
// Remove any optional parameters from the route
|
|
||||||
$path = preg_replace('`{/.*?}`i', '', $path);
|
$path = preg_replace('`{/.*?}`i', '', $path);
|
||||||
|
|
||||||
// Set the appropriate HTTP host
|
// Remove any optional parameters from the route
|
||||||
$host = $_SERVER['HTTP_HOST'];
|
// and replace them with existing route parameters, if they exist
|
||||||
|
$path_segments = explode('/', $path);
|
||||||
|
$segments = $this->segments();
|
||||||
|
|
||||||
return "//{$host}/{$path}";
|
for($i=0; $i<count($path_segments); $i++)
|
||||||
|
{
|
||||||
|
if ( ! array_key_exists($i + 1, $segments))
|
||||||
|
{
|
||||||
|
$segments[$i + 1] = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
$path_segments[$i] = preg_replace('`{.*?}`i', $segments[$i + 1], $path_segments[$i]);
|
||||||
|
}
|
||||||
|
$path = implode('/', $path_segments);
|
||||||
|
|
||||||
|
return "//{$this->host}/{$path}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,11 +99,11 @@ class UrlGenerator extends RoutingBase {
|
|||||||
public function default_url($type)
|
public function default_url($type)
|
||||||
{
|
{
|
||||||
$type = trim($type);
|
$type = trim($type);
|
||||||
$default_path = $this->__get("default_{$type}_path");
|
$default_path = $this->__get("default_{$type}_list_path");
|
||||||
|
|
||||||
if ( ! is_null($default_path))
|
if ( ! is_null($default_path))
|
||||||
{
|
{
|
||||||
return $this->url($default_path);
|
return $this->url("{$type}/{$default_path}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
@ -95,12 +123,6 @@ class UrlGenerator extends RoutingBase {
|
|||||||
// Remove beginning/trailing slashes
|
// Remove beginning/trailing slashes
|
||||||
$path = trim($path, '/');
|
$path = trim($path, '/');
|
||||||
|
|
||||||
// Remove any optional parameters from the route
|
|
||||||
$path = preg_replace('`{/.*?}`i', '', $path);
|
|
||||||
|
|
||||||
// Set the appropriate HTTP host
|
|
||||||
$host = $_SERVER['HTTP_HOST'];
|
|
||||||
|
|
||||||
// Set the default view
|
// Set the default view
|
||||||
if ($path === '')
|
if ($path === '')
|
||||||
{
|
{
|
||||||
@ -108,7 +130,7 @@ class UrlGenerator extends RoutingBase {
|
|||||||
if ($this->__get('default_to_list_view')) $path .= '/list';
|
if ($this->__get('default_to_list_view')) $path .= '/list';
|
||||||
}
|
}
|
||||||
|
|
||||||
return "//{$host}/{$path}";
|
return $this->url($path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// End of UrlGenerator.php
|
// End of UrlGenerator.php
|
@ -6,20 +6,6 @@ use Aviat\AnimeClient\UrlGenerator;
|
|||||||
|
|
||||||
class UrlGeneratorTest extends AnimeClient_TestCase {
|
class UrlGeneratorTest extends AnimeClient_TestCase {
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
$this->container = new Container([
|
|
||||||
'config' => new Config([
|
|
||||||
'foo' => 'bar',
|
|
||||||
'routing' => [
|
|
||||||
'asset_path' => '/assets',
|
|
||||||
],
|
|
||||||
'bar' => 'baz'
|
|
||||||
])
|
|
||||||
]);
|
|
||||||
$this->config = $this->container->get('config');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function assetUrlProvider()
|
public function assetUrlProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -140,5 +126,4 @@ class UrlGeneratorTest extends AnimeClient_TestCase {
|
|||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -28,7 +28,7 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
|
|||||||
'asset_path' => '//localhost/assets/',
|
'asset_path' => '//localhost/assets/',
|
||||||
'databaase' => [],
|
'databaase' => [],
|
||||||
'routing' => [
|
'routing' => [
|
||||||
|
'asset_path' => '/assets'
|
||||||
],
|
],
|
||||||
'routes' => [
|
'routes' => [
|
||||||
'convention' => [
|
'convention' => [
|
||||||
|
Loading…
Reference in New Issue
Block a user