Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/App/MetaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public function licenses()
'jsLibData' => file_get_contents(base_path('dev/licensing/js-library-licenses.txt')),
]);
}

/**
* Show the view for /opensearch.xml.
*/
public function opensearch()
{
return response()
->view('misc.opensearch')
->header('Content-Type', 'application/opensearchdescription+xml');
}
}
3 changes: 3 additions & 0 deletions lang/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@
// Not directly used but available for convenience to users.
'privacy_policy' => 'Privacy Policy',
'terms_of_service' => 'Terms of Service',

// OpenSearch
'opensearch_description' => 'Search :appName',
];
3 changes: 3 additions & 0 deletions resources/views/layouts/base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class="{{ setting()->getForCurrentUser('dark-mode-enabled') ? 'dark-mode ' : ''
<link rel="manifest" href="{{ url('/manifest.json') }}">
<meta name="mobile-web-app-capable" content="yes">

<!-- OpenSearch -->
<link rel="search" type="application/opensearchdescription+xml" title="{{ setting('app-name') }}" href="{{ url('/opensearch.xml') }}">

@yield('head')

<!-- Custom Styles & Head Content -->
Expand Down
12 changes: 12 additions & 0 deletions resources/views/misc/opensearch.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>{{ mb_strimwidth(setting('app-name'), 0, 16) }}</ShortName>
<Description>{{ trans('common.opensearch_description', ['appName' => setting('app-name')]) }}</Description>
<Image width="256" height="256" type="image/png">{{ setting('app-icon') ?: url('/icon.png') }}</Image>
<Image width="180" height="180" type="image/png">{{ setting('app-icon-180') ?: url('/icon-180.png') }}</Image>
<Image width="128" height="128" type="image/png">{{ setting('app-icon-128') ?: url('/icon-128.png') }}</Image>
<Image width="64" height="64" type="image/png">{{ setting('app-icon-64') ?: url('/icon-64.png') }}</Image>
<Image width="32" height="32" type="image/png">{{ setting('app-icon-32') ?: url('/icon-32.png') }}</Image>
<Url type="text/html" rel="results" template="{{ url('/search') }}?term={searchTerms}"/>
<Url type="application/opensearchdescription+xml" rel="self" template="{{ url('/opensearch.xml') }}"/>
</OpenSearchDescription>
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Route::get('/favicon.ico', [MetaController::class, 'favicon']);
Route::get('/manifest.json', [MetaController::class, 'pwaManifest']);
Route::get('/licenses', [MetaController::class, 'licenses']);
Route::get('/opensearch.xml', [MetaController::class, 'opensearch']);

// Authenticated routes...
Route::middleware('auth')->group(function () {
Expand Down
42 changes: 42 additions & 0 deletions tests/OpensearchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Tests;

class OpensearchTest extends TestCase
{
public function test_opensearch_endpoint()
{
$appName = setting('app-name');
$resultUrl = url('/search') . '?term={searchTerms}';
$selfUrl = url('/opensearch.xml');

$resp = $this->get('/opensearch.xml');
$resp->assertOk();

$html = $this->withHtml($resp);

$html->assertElementExists('OpenSearchDescription > ShortName');
$html->assertElementContains('OpenSearchDescription > ShortName', mb_strimwidth($appName, 0, 16));

$html->assertElementExists('OpenSearchDescription > Description');
$html->assertElementContains('OpenSearchDescription > Description', trans('common.opensearch_description', [
'appName' => $appName,
]));

$html->assertElementExists('OpenSearchDescription > Image');

$html->assertElementExists('OpenSearchDescription > Url[rel="results"][template="' . htmlspecialchars($resultUrl) . '"]');
$html->assertElementExists('OpenSearchDescription > Url[rel="self"][template="' . htmlspecialchars($selfUrl) . '"]');
}

public function test_opensearch_linked_to_from_home()
{
$appName = setting('app-name');
$endpointUrl = url('/opensearch.xml');

$resp = $this->asViewer()->get('/');
$html = $this->withHtml($resp);

$html->assertElementExists('head > link[rel="search"][type="application/opensearchdescription+xml"][title="' . htmlspecialchars($appName) . '"][href="' . htmlspecialchars($endpointUrl) . '"]');
}
}