Refactor URLs
This commit is contained in:
parent
f9be136345
commit
1e935123c1
6 changed files with 23 additions and 20 deletions
15
.htaccess
15
.htaccess
|
@ -4,14 +4,17 @@
|
||||||
<IfModule mod_rewrite.c>
|
<IfModule mod_rewrite.c>
|
||||||
RewriteEngine On
|
RewriteEngine On
|
||||||
|
|
||||||
# Wishlists / Wish
|
|
||||||
RewriteRule ^([a-z\-]+)/(\d+)$ /?page=$1&id=$2 [QSA,L]
|
|
||||||
|
|
||||||
# Wishlist
|
|
||||||
RewriteRule ^wishlist/([a-z0-9]+)$ /?wishlist=$1 [QSA,L]
|
|
||||||
|
|
||||||
# Page
|
# Page
|
||||||
RewriteRule ^([a-z\-]+)$ /?page=$1 [QSA,L]
|
RewriteRule ^([a-z\-]+)$ /?page=$1 [QSA,L]
|
||||||
|
|
||||||
|
# Wishlists (My lists)
|
||||||
|
RewriteRule ^(wishlists)/([0-9]+)$ /?page=$1&id=$2 [QSA,L]
|
||||||
|
|
||||||
|
# Wish
|
||||||
|
RewriteRule ^(wish)/(\d+)$ /?page=$1&id=$2 [QSA,L]
|
||||||
|
|
||||||
|
# Wishlist
|
||||||
|
RewriteRule ^(wishlist)/([0-9a-f]{40})$ /?page=$1&hash=$2 [QSA,L]
|
||||||
</IfModule>
|
</IfModule>
|
||||||
|
|
||||||
##-- When caching of gzipped JS and CSS files is used, enable this setting
|
##-- When caching of gzipped JS and CSS files is used, enable this setting
|
||||||
|
|
|
@ -148,13 +148,6 @@ if ($options && $options->getOption('isInstalled') && !(defined('ENV_IS_DEV') &&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Wishlist
|
|
||||||
*/
|
|
||||||
if (!isset($_SESSION['_GET']['page']) && isset($_SESSION['_GET']['wishlist'])) {
|
|
||||||
$page = 'wishlist';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page
|
* Page
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -49,7 +49,7 @@ $(function () {
|
||||||
if (wishlistValue) {
|
if (wishlistValue) {
|
||||||
wishlist.id = wishlistValue;
|
wishlist.id = wishlistValue;
|
||||||
|
|
||||||
$('.wishlist-share').attr('href', '/?wishlist=' + wishlists[wishlistIndex].hash);
|
$('.wishlist-share').attr('href', '/?page=wishlist&hash=' + wishlists[wishlistIndex].hash);
|
||||||
|
|
||||||
$('.button.wishlist-wish-add').removeClass('disabled');
|
$('.button.wishlist-wish-add').removeClass('disabled');
|
||||||
$('.button.wishlist-share').removeClass('disabled');
|
$('.button.wishlist-share').removeClass('disabled');
|
||||||
|
@ -65,7 +65,7 @@ $(function () {
|
||||||
.then(handleFetchError)
|
.then(handleFetchError)
|
||||||
.then(handleFetchResponse)
|
.then(handleFetchResponse)
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
window.history.pushState({}, '', response.data.url);
|
window.history.replaceState(null, document.title, response.data.url);
|
||||||
|
|
||||||
$('.ui.dropdown.filter.priority')
|
$('.ui.dropdown.filter.priority')
|
||||||
.dropdown('restore default value')
|
.dropdown('restore default value')
|
||||||
|
|
|
@ -164,7 +164,7 @@ class Page
|
||||||
if ($options && $options->getOption('isInstalled') && isset($_SESSION['_GET'])) {
|
if ($options && $options->getOption('isInstalled') && isset($_SESSION['_GET'])) {
|
||||||
$url = new URL(http_build_query($_SESSION['_GET']));
|
$url = new URL(http_build_query($_SESSION['_GET']));
|
||||||
|
|
||||||
if ($url->isPretty()) {
|
if (false === $url->isPretty()) {
|
||||||
redirect($url->getPretty());
|
redirect($url->getPretty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,18 @@ namespace wishthis;
|
||||||
|
|
||||||
class URL
|
class URL
|
||||||
{
|
{
|
||||||
public function __construct(private string $url)
|
public string $url;
|
||||||
|
|
||||||
|
public function __construct(string $url)
|
||||||
{
|
{
|
||||||
|
$this->url = urldecode($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isPretty(): bool
|
public function isPretty(): bool
|
||||||
{
|
{
|
||||||
return preg_match('/^\/\?.+?=.+?$/', $this->url);
|
$isPretty = 1 === preg_match('/^\/[a-z0-9\/]+/', $this->url);
|
||||||
|
|
||||||
|
return $isPretty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPermalink(): string
|
public function getPermalink(): string
|
||||||
|
@ -95,6 +100,8 @@ class URL
|
||||||
) {
|
) {
|
||||||
$rewriteRule = str_replace($match, $value, $rewriteRule);
|
$rewriteRule = str_replace($match, $value, $rewriteRule);
|
||||||
|
|
||||||
|
error_log('Successfully matched ' . $match . ' with ' . $value . ' New rule is now: ' . $rewriteRule);
|
||||||
|
|
||||||
$countMatches++;
|
$countMatches++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -114,6 +121,6 @@ class URL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pretty_url ?: '?' . $this->url;
|
return $pretty_url ?: '/?' . $this->url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
namespace wishthis;
|
namespace wishthis;
|
||||||
|
|
||||||
$wishlist = new Wishlist($_SESSION['_GET']['wishlist']);
|
$wishlist = new Wishlist($_SESSION['_GET']['hash']);
|
||||||
$page = new Page(__FILE__, $wishlist->getTitle());
|
$page = new Page(__FILE__, $wishlist->getTitle());
|
||||||
|
|
||||||
if (!$wishlist->exists) {
|
if (!$wishlist->exists) {
|
||||||
|
|
Loading…
Reference in a new issue