mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 19:38:40 +08:00
chore: adapt UrlGenerator
This commit is contained in:
parent
3b3efc7cbb
commit
9c3460a619
@ -36,7 +36,7 @@ class AkismetProvider extends AbstractServiceProvider
|
|||||||
|
|
||||||
return new Akismet(
|
return new Akismet(
|
||||||
$settings->get('flarum-akismet.api_key'),
|
$settings->get('flarum-akismet.api_key'),
|
||||||
$url->to('forum')->base(),
|
$url->base('forum'),
|
||||||
$app::VERSION,
|
$app::VERSION,
|
||||||
$extensions->getExtension('flarum-akismet')->getVersion() ?? 'unknown',
|
$extensions->getExtension('flarum-akismet')->getVersion() ?? 'unknown',
|
||||||
$config->inDebugMode()
|
$config->inDebugMode()
|
||||||
|
@ -50,7 +50,7 @@ class ConfigureMentions
|
|||||||
|
|
||||||
private function configureUserMentions(Configurator $config): void
|
private function configureUserMentions(Configurator $config): void
|
||||||
{
|
{
|
||||||
$config->rendering->parameters['PROFILE_URL'] = $this->url->to('forum')->route('user', ['username' => '']);
|
$config->rendering->parameters['PROFILE_URL'] = $this->url->route('forum.user', ['username' => '']);
|
||||||
|
|
||||||
$tagName = 'USERMENTION';
|
$tagName = 'USERMENTION';
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ class ConfigureMentions
|
|||||||
|
|
||||||
private function configurePostMentions(Configurator $config): void
|
private function configurePostMentions(Configurator $config): void
|
||||||
{
|
{
|
||||||
$config->rendering->parameters['DISCUSSION_URL'] = $this->url->to('forum')->route('discussion', ['id' => '']);
|
$config->rendering->parameters['DISCUSSION_URL'] = $this->url->route('forum.discussion', ['id' => '']);
|
||||||
|
|
||||||
$tagName = 'POSTMENTION';
|
$tagName = 'POSTMENTION';
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ class ConfigureMentions
|
|||||||
|
|
||||||
private function configureTagMentions(Configurator $config): void
|
private function configureTagMentions(Configurator $config): void
|
||||||
{
|
{
|
||||||
$config->rendering->parameters['TAG_URL'] = $this->url->to('forum')->route('tag', ['slug' => '']);
|
$config->rendering->parameters['TAG_URL'] = $this->url->route('forum.tag', ['slug' => '']);
|
||||||
|
|
||||||
$tagName = 'TAGMENTION';
|
$tagName = 'TAGMENTION';
|
||||||
|
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
'{recipient_display_name}' => $user->display_name,
|
'{recipient_display_name}' => $user->display_name,
|
||||||
'{mentioner_display_name}' => $blueprint->post->user->display_name,
|
'{mentioner_display_name}' => $blueprint->post->user->display_name,
|
||||||
'{title}' => $blueprint->post->discussion->title,
|
'{title}' => $blueprint->post->discussion->title,
|
||||||
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number]),
|
'{url}' => $url->route('forum.discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number]),
|
||||||
'{content}' => $blueprint->post->content
|
'{content}' => $blueprint->post->content
|
||||||
]) !!}
|
]) !!}
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
'{replier_display_name}' => $blueprint->reply->user->display_name,
|
'{replier_display_name}' => $blueprint->reply->user->display_name,
|
||||||
'{post_number}' => $blueprint->post->number,
|
'{post_number}' => $blueprint->post->number,
|
||||||
'{title}' => $blueprint->post->discussion->title,
|
'{title}' => $blueprint->post->discussion->title,
|
||||||
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->reply->discussion_id, 'near' => $blueprint->reply->number]),
|
'{url}' => $url->route('forum.discussion', ['id' => $blueprint->reply->discussion_id, 'near' => $blueprint->reply->number]),
|
||||||
'{content}' => $blueprint->reply->content
|
'{content}' => $blueprint->reply->content
|
||||||
]) !!}
|
]) !!}
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
'{recipient_display_name}' => $user->display_name,
|
'{recipient_display_name}' => $user->display_name,
|
||||||
'{mentioner_display_name}' => $blueprint->post->user->display_name,
|
'{mentioner_display_name}' => $blueprint->post->user->display_name,
|
||||||
'{title}' => $blueprint->post->discussion->title,
|
'{title}' => $blueprint->post->discussion->title,
|
||||||
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number]),
|
'{url}' => $url->route('forum.discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number]),
|
||||||
'{content}' => $blueprint->post->content
|
'{content}' => $blueprint->post->content
|
||||||
]) !!}
|
]) !!}
|
||||||
|
@ -48,7 +48,7 @@ class ListTasksController extends AbstractListController
|
|||||||
$document->addMeta('total', (string) $total);
|
$document->addMeta('total', (string) $total);
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->to('api')->route('package-manager.tasks.index'),
|
$this->url->route('api.package-manager.tasks.index'),
|
||||||
$request->query(),
|
$request->query(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
'{recipient_display_name}' => $user->display_name,
|
'{recipient_display_name}' => $user->display_name,
|
||||||
'{poster_display_name}' => $blueprint->post->user->display_name,
|
'{poster_display_name}' => $blueprint->post->user->display_name,
|
||||||
'{title}' => $blueprint->post->discussion->title,
|
'{title}' => $blueprint->post->discussion->title,
|
||||||
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number]),
|
'{url}' => $url->route('forum.discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number]),
|
||||||
'{content}' => $blueprint->post->content
|
'{content}' => $blueprint->post->content
|
||||||
]) !!}
|
]) !!}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{!! $translator->trans('flarum-suspend.email.unsuspended.body', [
|
{!! $translator->trans('flarum-suspend.email.unsuspended.body', [
|
||||||
'{recipient_display_name}' => $user->display_name,
|
'{recipient_display_name}' => $user->display_name,
|
||||||
'{forum_url}' => $url->to('forum')->base(),
|
'{forum_url}' => $url->base('forum'),
|
||||||
]) !!}
|
]) !!}
|
||||||
|
@ -57,7 +57,7 @@ class ListTagsController extends AbstractListController
|
|||||||
$tags = $results->getResults();
|
$tags = $results->getResults();
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->to('api')->route('tags.index'),
|
$this->url->route('api.tags.index'),
|
||||||
$request->query(),
|
$request->query(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
|
@ -50,7 +50,7 @@ class Tags
|
|||||||
$document->title = $this->translator->trans('flarum-tags.forum.all_tags.meta_title_text');
|
$document->title = $this->translator->trans('flarum-tags.forum.all_tags.meta_title_text');
|
||||||
$document->meta['description'] = $this->translator->trans('flarum-tags.forum.all_tags.meta_description_text');
|
$document->meta['description'] = $this->translator->trans('flarum-tags.forum.all_tags.meta_description_text');
|
||||||
$document->content = $this->view->make('tags::frontend.content.tags', compact('primaryTags', 'secondaryTags', 'children'));
|
$document->content = $this->view->make('tags::frontend.content.tags', compact('primaryTags', 'secondaryTags', 'children'));
|
||||||
$document->canonicalUrl = $this->url->to('forum')->base().($defaultRoute === '/tags' ? '' : $request->getUri());
|
$document->canonicalUrl = $this->url->base('forum').($defaultRoute === '/tags' ? '' : $request->getUri());
|
||||||
$document->payload['apiDocument'] = $apiDocument;
|
$document->payload['apiDocument'] = $apiDocument;
|
||||||
|
|
||||||
return $document;
|
return $document;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
@foreach ($apiDocument->data as $discussion)
|
@foreach ($apiDocument->data as $discussion)
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ $url->to('forum')->route('discussion', [
|
<a href="{{ $url->route('forum.discussion', [
|
||||||
'id' => $discussion->attributes->slug
|
'id' => $discussion->attributes->slug
|
||||||
]) }}">
|
]) }}">
|
||||||
{{ $discussion->attributes->title }}
|
{{ $discussion->attributes->title }}
|
||||||
@ -17,10 +17,10 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@if (isset($apiDocument->links->prev))
|
@if (isset($apiDocument->links->prev))
|
||||||
<a href="{{ $url->to('forum')->route('tag', ['slug' => $tag->slug]) }}?page={{ $page - 1 }}">« {{ $translator->trans('core.views.index.previous_page_button') }}</a>
|
<a href="{{ $url->route('forum.tag', ['slug' => $tag->slug]) }}?page={{ $page - 1 }}">« {{ $translator->trans('core.views.index.previous_page_button') }}</a>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if (isset($apiDocument->links->next))
|
@if (isset($apiDocument->links->next))
|
||||||
<a href="{{ $url->to('forum')->route('tag', ['slug' => $tag->slug]) }}?page={{ $page + 1 }}">{{ $translator->trans('core.views.index.next_page_button') }} »</a>
|
<a href="{{ $url->route('forum.tag', ['slug' => $tag->slug]) }}?page={{ $page + 1 }}">{{ $translator->trans('core.views.index.next_page_button') }} »</a>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
@foreach ($category->pluck('attributes', 'id') as $id => $tag)
|
@foreach ($category->pluck('attributes', 'id') as $id => $tag)
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ $url->to('forum')->route('tag', [
|
<a href="{{ $url->route('forum.tag', [
|
||||||
'slug' => $tag['slug']
|
'slug' => $tag['slug']
|
||||||
]) }}">
|
]) }}">
|
||||||
{{ $tag['name'] }}
|
{{ $tag['name'] }}
|
||||||
@ -17,7 +17,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
@foreach ($children->get($id) as $child)
|
@foreach ($children->get($id) as $child)
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ $url->to('forum')->route('tag', [
|
<a href="{{ $url->route('forum.tag', [
|
||||||
'slug' => $child['attributes']['slug']
|
'slug' => $child['attributes']['slug']
|
||||||
]) }}">
|
]) }}">
|
||||||
{{ $child['attributes']['name'] }}
|
{{ $child['attributes']['name'] }}
|
||||||
|
@ -43,9 +43,10 @@ class AdminServiceProvider extends AbstractServiceProvider
|
|||||||
|
|
||||||
$factory = $container->make(RouteHandlerFactory::class);
|
$factory = $container->make(RouteHandlerFactory::class);
|
||||||
|
|
||||||
$router->middleware('admin')->prefix($config->path('admin'))->group(
|
$router->middleware('admin')
|
||||||
fn (Router $router) => (include __DIR__.'/routes.php')($router, $factory)
|
->prefix($config->path('admin'))
|
||||||
);
|
->name('admin.')
|
||||||
|
->group(fn (Router $router) => (include __DIR__.'/routes.php')($router, $factory));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->container->singleton('flarum.admin.middleware', function () {
|
$this->container->singleton('flarum.admin.middleware', function () {
|
||||||
|
@ -34,6 +34,6 @@ class UpdateExtensionController extends AbstractController
|
|||||||
new ToggleExtension($actor, $name, $enabled)
|
new ToggleExtension($actor, $name, $enabled)
|
||||||
);
|
);
|
||||||
|
|
||||||
return new RedirectResponse($this->url->to('admin')->base());
|
return new RedirectResponse($this->url->base('admin'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,10 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||||||
|
|
||||||
$router->middlewareGroup('api', $container->make('flarum.api.middleware'));
|
$router->middlewareGroup('api', $container->make('flarum.api.middleware'));
|
||||||
|
|
||||||
$router->middleware('api')->prefix($config->path('api'))->group(
|
$router->middleware('api')
|
||||||
fn (Router $router) => (include __DIR__.'/routes.php')($router)
|
->prefix($config->path('api'))
|
||||||
);
|
->name('api.')
|
||||||
|
->group(fn (Router $router) => (include __DIR__.'/routes.php')($router));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->container->singleton('flarum.api.throttlers', function () {
|
$this->container->singleton('flarum.api.throttlers', function () {
|
||||||
|
@ -40,7 +40,7 @@ class ListAccessTokensController extends AbstractListController
|
|||||||
$tokens = $this->filterer->filter(new QueryCriteria($actor, $filter), $limit, $offset);
|
$tokens = $this->filterer->filter(new QueryCriteria($actor, $filter), $limit, $offset);
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->to('api')->route('access-tokens.index'),
|
$this->url->route('api.access-tokens.index'),
|
||||||
$request->query(),
|
$request->query(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
|
@ -65,7 +65,7 @@ class ListDiscussionsController extends AbstractListController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->to('api')->route('discussions.index'),
|
$this->url->route('api.discussions.index'),
|
||||||
$request->query(),
|
$request->query(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
|
@ -47,7 +47,7 @@ class ListGroupsController extends AbstractListController
|
|||||||
$queryResults = $this->filterer->filter($criteria, $limit, $offset);
|
$queryResults = $this->filterer->filter($criteria, $limit, $offset);
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->to('api')->route('groups.index'),
|
$this->url->route('api.groups.index'),
|
||||||
$request->query(),
|
$request->query(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
|
@ -63,7 +63,7 @@ class ListNotificationsController extends AbstractListController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->to('api')->route('notifications.index'),
|
$this->url->route('api.notifications.index'),
|
||||||
$request->query(),
|
$request->query(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
|
@ -56,7 +56,7 @@ class ListPostsController extends AbstractListController
|
|||||||
$results = $this->filterer->filter(new QueryCriteria($actor, $filters, $sort, $sortIsDefault), $limit, $offset);
|
$results = $this->filterer->filter(new QueryCriteria($actor, $filters, $sort, $sortIsDefault), $limit, $offset);
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->to('api')->route('posts.index'),
|
$this->url->route('api.posts.index'),
|
||||||
$request->query(),
|
$request->query(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
|
@ -68,7 +68,7 @@ class ListUsersController extends AbstractListController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->to('api')->route('users.index'),
|
$this->url->route('api.users.index'),
|
||||||
$request->query(),
|
$request->query(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
|
@ -69,11 +69,11 @@ class ForumSerializer extends AbstractSerializer
|
|||||||
'title' => $this->settings->get('forum_title'),
|
'title' => $this->settings->get('forum_title'),
|
||||||
'description' => $this->settings->get('forum_description'),
|
'description' => $this->settings->get('forum_description'),
|
||||||
'showLanguageSelector' => (bool) $this->settings->get('show_language_selector', true),
|
'showLanguageSelector' => (bool) $this->settings->get('show_language_selector', true),
|
||||||
'baseUrl' => $url = $this->url->to('forum')->base(),
|
'baseUrl' => $url = $this->url->base('forum'),
|
||||||
'basePath' => $path = parse_url($url, PHP_URL_PATH) ?: '',
|
'basePath' => $path = parse_url($url, PHP_URL_PATH) ?: '',
|
||||||
'baseOrigin' => substr($url, 0, strlen($url) - strlen($path)),
|
'baseOrigin' => substr($url, 0, strlen($url) - strlen($path)),
|
||||||
'debug' => $this->config->inDebugMode(),
|
'debug' => $this->config->inDebugMode(),
|
||||||
'apiUrl' => $this->url->to('api')->base(),
|
'apiUrl' => $this->url->base('api'),
|
||||||
'welcomeTitle' => $this->settings->get('welcome_title'),
|
'welcomeTitle' => $this->settings->get('welcome_title'),
|
||||||
'welcomeMessage' => $this->settings->get('welcome_message'),
|
'welcomeMessage' => $this->settings->get('welcome_message'),
|
||||||
'themePrimaryColor' => $this->settings->get('theme_primary_color'),
|
'themePrimaryColor' => $this->settings->get('theme_primary_color'),
|
||||||
@ -94,7 +94,7 @@ class ForumSerializer extends AbstractSerializer
|
|||||||
];
|
];
|
||||||
|
|
||||||
if ($this->actor->can('administrate')) {
|
if ($this->actor->can('administrate')) {
|
||||||
$attributes['adminUrl'] = $this->url->to('admin')->base();
|
$attributes['adminUrl'] = $this->url->base('admin');
|
||||||
$attributes['version'] = Application::VERSION;
|
$attributes['version'] = Application::VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ trait ExtendsRoutes
|
|||||||
$router
|
$router
|
||||||
->addRoute($route['method'], $route['path'], $action)
|
->addRoute($route['method'], $route['path'], $action)
|
||||||
->prefix($config->path($this->frontend))
|
->prefix($config->path($this->frontend))
|
||||||
->name($route['name']);
|
->name("$this->frontend.{$route['name']}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -46,7 +46,7 @@ class Filesystem implements ExtenderInterface
|
|||||||
* ->disk('flarum-uploads', function (Paths $paths, UrlGenerator $url) {
|
* ->disk('flarum-uploads', function (Paths $paths, UrlGenerator $url) {
|
||||||
* return [
|
* return [
|
||||||
* 'root' => "$paths->public/assets/uploads",
|
* 'root' => "$paths->public/assets/uploads",
|
||||||
* 'url' => $url->to('forum')->path('assets/uploads')
|
* 'url' => $url->path('forum', 'assets/uploads')
|
||||||
* ];
|
* ];
|
||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
|
@ -119,7 +119,7 @@ class Theme implements ExtenderInterface
|
|||||||
* (new Extend\Theme())
|
* (new Extend\Theme())
|
||||||
* ->addCustomLessVariable('my-extension__asset_path', function () {
|
* ->addCustomLessVariable('my-extension__asset_path', function () {
|
||||||
* $url = resolve(UrlGenerator::class);
|
* $url = resolve(UrlGenerator::class);
|
||||||
* $assetUrl = $url->to('forum')->base().'/assets/extensions/my-extension/my-asset.jpg';
|
* $assetUrl = $url->base('forum').'/assets/extensions/my-extension/my-asset.jpg';
|
||||||
* return "\"$assetUrl\"";
|
* return "\"$assetUrl\"";
|
||||||
* })
|
* })
|
||||||
* ```
|
* ```
|
||||||
|
@ -35,14 +35,14 @@ class FilesystemServiceProvider extends AbstractServiceProvider
|
|||||||
'flarum-assets' => function (Paths $paths, UrlGenerator $url) {
|
'flarum-assets' => function (Paths $paths, UrlGenerator $url) {
|
||||||
return [
|
return [
|
||||||
'root' => "$paths->public/assets",
|
'root' => "$paths->public/assets",
|
||||||
'url' => $url->to('forum')->path('assets'),
|
'url' => $url->path('forum', 'assets'),
|
||||||
'visibility' => Visibility::PUBLIC
|
'visibility' => Visibility::PUBLIC
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
'flarum-avatars' => function (Paths $paths, UrlGenerator $url) {
|
'flarum-avatars' => function (Paths $paths, UrlGenerator $url) {
|
||||||
return [
|
return [
|
||||||
'root' => "$paths->public/assets/avatars",
|
'root' => "$paths->public/assets/avatars",
|
||||||
'url' => $url->to('forum')->path('assets/avatars')
|
'url' => $url->path('forum', 'assets/avatars')
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -60,7 +60,7 @@ class Discussion
|
|||||||
|
|
||||||
$queryString = http_build_query($newQueryParams);
|
$queryString = http_build_query($newQueryParams);
|
||||||
|
|
||||||
return $this->url->to('forum')->route('discussion', ['id' => $apiDocument->data->attributes->slug]).
|
return $this->url->route('forum.discussion', ['id' => $apiDocument->data->attributes->slug]).
|
||||||
($queryString ? '?'.$queryString : '');
|
($queryString ? '?'.$queryString : '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class Index
|
|||||||
$document->content = $this->view->make('flarum.forum::frontend.content.index', compact('apiDocument', 'page'));
|
$document->content = $this->view->make('flarum.forum::frontend.content.index', compact('apiDocument', 'page'));
|
||||||
$document->payload['apiDocument'] = $apiDocument;
|
$document->payload['apiDocument'] = $apiDocument;
|
||||||
|
|
||||||
$document->canonicalUrl = $this->url->to('forum')->base().($defaultRoute === '/all' ? '' : $request->getUri()->getPath());
|
$document->canonicalUrl = $this->url->base('forum').($defaultRoute === '/all' ? '' : $request->getUri()->getPath());
|
||||||
$document->page = $page;
|
$document->page = $page;
|
||||||
$document->hasNextPage = isset($apiDocument->links->next);
|
$document->hasNextPage = isset($apiDocument->links->next);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class User
|
|||||||
$user = $apiDocument->data->attributes;
|
$user = $apiDocument->data->attributes;
|
||||||
|
|
||||||
$document->title = $user->displayName;
|
$document->title = $user->displayName;
|
||||||
$document->canonicalUrl = $this->url->to('forum')->route('user', ['username' => $user->slug]);
|
$document->canonicalUrl = $this->url->route('forum.user', ['username' => $user->slug]);
|
||||||
$document->payload['apiDocument'] = $apiDocument;
|
$document->payload['apiDocument'] = $apiDocument;
|
||||||
|
|
||||||
return $document;
|
return $document;
|
||||||
|
@ -40,6 +40,6 @@ class ConfirmEmailController extends AbstractController
|
|||||||
$token = SessionAccessToken::generate($user->id);
|
$token = SessionAccessToken::generate($user->id);
|
||||||
$this->authenticator->logIn($session, $token);
|
$this->authenticator->logIn($session, $token);
|
||||||
|
|
||||||
return new RedirectResponse($this->url->to('forum')->base());
|
return new RedirectResponse($this->url->base('forum'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ class LogOutController extends AbstractController
|
|||||||
$session = $request->attributes->get('session');
|
$session = $request->attributes->get('session');
|
||||||
$actor = RequestUtil::getActor($request);
|
$actor = RequestUtil::getActor($request);
|
||||||
|
|
||||||
$url = $request->query('return', $this->url->to('forum')->base());
|
$url = $request->query('return', $this->url->base('forum'));
|
||||||
|
|
||||||
// If there is no user logged in, return to the index.
|
// If there is no user logged in, return to the index.
|
||||||
if ($actor->isGuest()) {
|
if ($actor->isGuest()) {
|
||||||
@ -54,7 +54,7 @@ class LogOutController extends AbstractController
|
|||||||
$return = $request->query('return');
|
$return = $request->query('return');
|
||||||
|
|
||||||
$view = $this->view->make('flarum.forum::log-out')
|
$view = $this->view->make('flarum.forum::log-out')
|
||||||
->with('url', $this->url->to('forum')->route('logout').'?token='.$csrfToken.($return ? '&return='.urlencode($return) : ''));
|
->with('url', $this->url->route('forum.logout').'?token='.$csrfToken.($return ? '&return='.urlencode($return) : ''));
|
||||||
|
|
||||||
return new HtmlResponse($view->render());
|
return new HtmlResponse($view->render());
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class SavePasswordController extends AbstractController
|
|||||||
$request->attributes->get('session')->put('errors', new MessageBag($e->errors()));
|
$request->attributes->get('session')->put('errors', new MessageBag($e->errors()));
|
||||||
|
|
||||||
// @todo: must return a 422 instead, look into renderable exceptions.
|
// @todo: must return a 422 instead, look into renderable exceptions.
|
||||||
return new RedirectResponse($this->url->to('forum')->route('resetPassword', ['token' => $token->token]));
|
return new RedirectResponse($this->url->route('forum.resetPassword', ['token' => $token->token]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$token->user->changePassword($password);
|
$token->user->changePassword($password);
|
||||||
@ -72,6 +72,6 @@ class SavePasswordController extends AbstractController
|
|||||||
$accessToken = SessionAccessToken::generate($token->user->id);
|
$accessToken = SessionAccessToken::generate($token->user->id);
|
||||||
$this->authenticator->logIn($session, $accessToken);
|
$this->authenticator->logIn($session, $accessToken);
|
||||||
|
|
||||||
return new RedirectResponse($this->url->to('forum')->base());
|
return new RedirectResponse($this->url->base('forum'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,9 +50,10 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||||||
|
|
||||||
$factory = $container->make(RouteHandlerFactory::class);
|
$factory = $container->make(RouteHandlerFactory::class);
|
||||||
|
|
||||||
$router->middleware('forum')->prefix($config->path('forum'))->group(
|
$router->middleware('forum')
|
||||||
fn (Router $router) => (include __DIR__.'/routes.php')($router, $factory)
|
->prefix($config->path('forum'))
|
||||||
);
|
->name('forum.')
|
||||||
|
->group(fn (Router $router) => (include __DIR__.'/routes.php')($router, $factory));
|
||||||
|
|
||||||
$this->setDefaultRoute(
|
$this->setDefaultRoute(
|
||||||
$router,
|
$router,
|
||||||
|
@ -210,13 +210,14 @@ class Application extends IlluminateContainer implements LaravelApplication
|
|||||||
'filesystem' => [\Illuminate\Filesystem\FilesystemManager::class, \Illuminate\Contracts\Filesystem\Factory::class],
|
'filesystem' => [\Illuminate\Filesystem\FilesystemManager::class, \Illuminate\Contracts\Filesystem\Factory::class],
|
||||||
'filesystem.disk' => [\Illuminate\Contracts\Filesystem\Filesystem::class],
|
'filesystem.disk' => [\Illuminate\Contracts\Filesystem\Filesystem::class],
|
||||||
'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class],
|
'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class],
|
||||||
'flarum' => [\Illuminate\Contracts\Container\Container::class, \Illuminate\Contracts\Foundation\Application::class, \Psr\Container\ContainerInterface::class, self::class],
|
'flarum' => [self::class, \Illuminate\Contracts\Container\Container::class, \Illuminate\Contracts\Foundation\Application::class, \Psr\Container\ContainerInterface::class],
|
||||||
'flarum.paths' => [Paths::class],
|
'flarum.paths' => [Paths::class],
|
||||||
'hash' => [\Illuminate\Contracts\Hashing\Hasher::class],
|
'hash' => [\Illuminate\Contracts\Hashing\Hasher::class],
|
||||||
'mailer' => [\Illuminate\Mail\Mailer::class, \Illuminate\Contracts\Mail\Mailer::class, \Illuminate\Contracts\Mail\MailQueue::class],
|
'mailer' => [\Illuminate\Mail\Mailer::class, \Illuminate\Contracts\Mail\Mailer::class, \Illuminate\Contracts\Mail\MailQueue::class],
|
||||||
'router' => [\Flarum\Http\Router::class, \Illuminate\Routing\Router::class, \Illuminate\Contracts\Routing\Registrar::class, \Illuminate\Contracts\Routing\BindingRegistrar::class],
|
'router' => [\Flarum\Http\Router::class, \Illuminate\Routing\Router::class, \Illuminate\Contracts\Routing\Registrar::class, \Illuminate\Contracts\Routing\BindingRegistrar::class],
|
||||||
'session' => [\Illuminate\Session\SessionManager::class],
|
'session' => [\Illuminate\Session\SessionManager::class],
|
||||||
'session.store' => [\Illuminate\Session\Store::class, \Illuminate\Contracts\Session\Session::class],
|
'session.store' => [\Illuminate\Session\Store::class, \Illuminate\Contracts\Session\Session::class],
|
||||||
|
'url' => [\Flarum\Http\UrlGenerator::class, \Illuminate\Routing\UrlGenerator::class, \Illuminate\Contracts\Routing\UrlGenerator::class],
|
||||||
'validator' => [\Illuminate\Validation\Factory::class, \Illuminate\Contracts\Validation\Factory::class],
|
'validator' => [\Illuminate\Validation\Factory::class, \Illuminate\Contracts\Validation\Factory::class],
|
||||||
'view' => [\Illuminate\View\Factory::class, \Illuminate\Contracts\View\Factory::class],
|
'view' => [\Illuminate\View\Factory::class, \Illuminate\Contracts\View\Factory::class],
|
||||||
];
|
];
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* For detailed copyright and license information, please view the
|
|
||||||
* LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Flarum\Http;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
class RouteCollectionUrlGenerator
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
protected string $baseUrl,
|
|
||||||
protected RouteCollection $routes
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function route(string $name, array $parameters = []): string
|
|
||||||
{
|
|
||||||
$path = $this->routes->getPath($name, $parameters);
|
|
||||||
$path = ltrim($path, '/');
|
|
||||||
|
|
||||||
return $this->baseUrl.'/'.$path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function path(string $path): string
|
|
||||||
{
|
|
||||||
return $this->baseUrl.'/'.$path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function base(): string
|
|
||||||
{
|
|
||||||
return $this->baseUrl;
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,4 +13,22 @@ class RoutingServiceProvider extends IlluminateRoutingServiceProvider
|
|||||||
return new Router($container['events'], $container);
|
return new Router($container['events'], $container);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function registerUrlGenerator(): void
|
||||||
|
{
|
||||||
|
$this->app->singleton('url', function (Container $container) {
|
||||||
|
$routes = $container['router']->getRoutes();
|
||||||
|
|
||||||
|
// The URL generator needs the route collection that exists on the router.
|
||||||
|
// Keep in mind this is an object, so we're passing by references here
|
||||||
|
// and all the registered routes will be available to the generator.
|
||||||
|
$container->instance('routes', $routes);
|
||||||
|
|
||||||
|
return new UrlGenerator(
|
||||||
|
$routes, $container->rebinding(
|
||||||
|
'request', $this->requestRebinder()
|
||||||
|
), $container['config']['app.asset_url']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,43 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* For detailed copyright and license information, please view the
|
|
||||||
* LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Flarum\Http;
|
namespace Flarum\Http;
|
||||||
|
|
||||||
use Flarum\Foundation\Application;
|
use Flarum\Foundation\Config;
|
||||||
|
use Illuminate\Routing\UrlGenerator as IlluminateUrlGenerator;
|
||||||
|
|
||||||
class UrlGenerator
|
class UrlGenerator extends IlluminateUrlGenerator
|
||||||
{
|
{
|
||||||
protected array $routes = [];
|
protected Config $config;
|
||||||
|
|
||||||
public function __construct(
|
public function setConfig(Config $config): void
|
||||||
protected Application $app
|
{
|
||||||
) {
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function base(string $frontend): string
|
||||||
* Register a named route collection for URL generation.
|
|
||||||
*/
|
|
||||||
public function addCollection(string $key, RouteCollection $routes, ?string $prefix = null): static
|
|
||||||
{
|
{
|
||||||
$this->routes[$key] = new RouteCollectionUrlGenerator(
|
$url = $this->config->url();
|
||||||
$this->app->url($prefix),
|
|
||||||
$routes
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this;
|
if ($frontend) {
|
||||||
|
$url .= '/'.$this->config->path($frontend);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function path(string $frontend, string $path): string
|
||||||
* Retrieve a URL generator instance for the given named route collection.
|
|
||||||
*/
|
|
||||||
public function to(string $collection): RouteCollectionUrlGenerator
|
|
||||||
{
|
{
|
||||||
return $this->routes[$collection];
|
return $this->base($frontend).'/'.ltrim($path, '/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ trait AccountActivationMailerTrait
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'username' => $user->display_name,
|
'username' => $user->display_name,
|
||||||
'url' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->token]),
|
'url' => $this->url->route('forum.confirmEmail', ['token' => $token->token]),
|
||||||
'forum' => $this->settings->get('forum_title')
|
'forum' => $this->settings->get('forum_title')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ class EmailConfirmationMailer
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'username' => $user->display_name,
|
'username' => $user->display_name,
|
||||||
'url' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->token]),
|
'url' => $this->url->route('forum.confirmEmail', ['token' => $token->token]),
|
||||||
'forum' => $this->settings->get('forum_title')
|
'forum' => $this->settings->get('forum_title')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class RequestPasswordResetJob extends AbstractJob
|
|||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'username' => $user->display_name,
|
'username' => $user->display_name,
|
||||||
'url' => $url->to('forum')->route('resetPassword', ['token' => $token->token]),
|
'url' => $url->route('forum.resetPassword', ['token' => $token->token]),
|
||||||
'forum' => $settings->get('forum_title'),
|
'forum' => $settings->get('forum_title'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class FilesystemTest extends TestCase
|
|||||||
$this->extend((new Extend\Filesystem)->disk('flarum-uploads', function (Paths $paths, UrlGenerator $url) {
|
$this->extend((new Extend\Filesystem)->disk('flarum-uploads', function (Paths $paths, UrlGenerator $url) {
|
||||||
return [
|
return [
|
||||||
'root' => "$paths->public/assets/uploads",
|
'root' => "$paths->public/assets/uploads",
|
||||||
'url' => $url->to('forum')->path('assets/uploads')
|
'url' => $url->path('forum', 'assets/uploads')
|
||||||
];
|
];
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ class UploadsDisk
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'root' => "$paths->public/assets/uploads",
|
'root' => "$paths->public/assets/uploads",
|
||||||
'url' => $url->to('forum')->path('assets/uploads')
|
'url' => $url->path('forum', 'assets/uploads')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
{{ $message }}
|
{{ $message }}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<a href="{{ $url->to('forum')->base() }}">
|
<a href="{{ $url->base('forum') }}">
|
||||||
{{ $translator->trans('core.views.error.not_found_return_link', ['forum' => $settings->get('forum_title')]) }}
|
{{ $translator->trans('core.views.error.not_found_return_link', ['forum' => $settings->get('forum_title')]) }}
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
<span class="ExtensionListItem-Dot {{ $isEnabled ? 'enabled' : 'disabled' }}" aria-hidden="true"></span>
|
<span class="ExtensionListItem-Dot {{ $isEnabled ? 'enabled' : 'disabled' }}" aria-hidden="true"></span>
|
||||||
</td>
|
</td>
|
||||||
<td class="NoJs-ExtensionsTable-toggle Table-controls">
|
<td class="NoJs-ExtensionsTable-toggle Table-controls">
|
||||||
<form action="{{ $url->to('admin')->route('extensions.update', ['name' => $extension->getId()]) }}" method="POST">
|
<form action="{{ $url->route('admin.extensions.update', ['name' => $extension->getId()]) }}" method="POST">
|
||||||
<input type="hidden" name="csrfToken" value="{{ $csrfToken }}">
|
<input type="hidden" name="csrfToken" value="{{ $csrfToken }}">
|
||||||
<input type="hidden" name="enabled" value="{{ $isEnabled ? 0 : 1 }}">
|
<input type="hidden" name="enabled" value="{{ $isEnabled ? 0 : 1 }}">
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
@foreach ($apiDocument->data as $discussion)
|
@foreach ($apiDocument->data as $discussion)
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ $url->to('forum')->route('discussion', [
|
<a href="{{ $url->route('forum.discussion', [
|
||||||
'id' => $discussion->attributes->slug
|
'id' => $discussion->attributes->slug
|
||||||
]) }}">
|
]) }}">
|
||||||
{{ $discussion->attributes->title }}
|
{{ $discussion->attributes->title }}
|
||||||
@ -16,10 +16,10 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@if (isset($apiDocument->links->prev))
|
@if (isset($apiDocument->links->prev))
|
||||||
<a href="{{ $url->to('forum')->route('index') }}?page={{ $page - 1 }}">« {{ $translator->trans('core.views.index.previous_page_button') }}</a>
|
<a href="{{ $url->route('forum.index') }}?page={{ $page - 1 }}">« {{ $translator->trans('core.views.index.previous_page_button') }}</a>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if (isset($apiDocument->links->next))
|
@if (isset($apiDocument->links->next))
|
||||||
<a href="{{ $url->to('forum')->route('index') }}?page={{ $page + 1 }}">{{ $translator->trans('core.views.index.next_page_button') }} »</a>
|
<a href="{{ $url->route('forum.index') }}?page={{ $page + 1 }}">{{ $translator->trans('core.views.index.next_page_button') }} »</a>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<form class="form" method="POST" action="{{ $url->to('forum')->route('savePassword') }}">
|
<form class="form" method="POST" action="{{ $url->route('forum.savePassword') }}">
|
||||||
<input type="hidden" name="csrfToken" value="{{ $csrfToken }}">
|
<input type="hidden" name="csrfToken" value="{{ $csrfToken }}">
|
||||||
<input type="hidden" name="passwordToken" value="{{ $passwordToken }}">
|
<input type="hidden" name="passwordToken" value="{{ $passwordToken }}">
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user