Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudloff committed Feb 20, 2022
2 parents cf82f1c + bc14b6e commit 3ab22c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
21 changes: 21 additions & 0 deletions classes/Factory/ViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ private static function getCanonicalUrl(Request $request): string
->withScheme('https');
}

/**
* @param Uri $uri
* @return Uri
*/
private static function cleanBasePath(Uri $uri): Uri
{
$basePath = $uri->getBasePath();
if (str_ends_with($basePath, 'index.php')) {
/*
* When the base path ends with index.php,
* routing works correctly, but it breaks the URL of static assets using {base_url}.
* So we alter the base path but only in the URI used by SmartyPlugins.
*/
$uri = $uri->withBasePath(dirname($basePath));
}

return $uri;
}

/**
* Create Smarty view object.
*
Expand Down Expand Up @@ -76,6 +95,8 @@ public static function create(ContainerInterface $container, Request $request =
/** @var LocaleManager $localeManager */
$localeManager = $container->get('locale');

$uri = self::cleanBasePath($uri);

$smartyPlugins = new SmartyPlugins($container->get('router'), $uri->withUserInfo(''));
$view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']);
$view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']);
Expand Down
5 changes: 0 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
use Alltube\App;
use Alltube\ErrorHandler;

if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
header('Location: ' . str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI']));
die;
}

try {
// Create app.
$app = new App();
Expand Down
2 changes: 1 addition & 1 deletion templates/inc/logo.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1 class="logobis">
<a class="logocompatible" href="{base_url}">
<a class="logocompatible" href="{path_for name="index"}">
<span class="logocompatiblemask"><img src="{base_url}/img/logocompatiblemask.png" width="447" height="107"
alt="{$config->appName}"/></span>
</a></h1>

0 comments on commit 3ab22c6

Please # to comment.