Skip to content

Commit

Permalink
fix: Fix sharing to Flus through the PWA
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Nov 13, 2024
1 parent e247e16 commit ef66025
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 17 deletions.
Binary file modified locales/fr_FR/LC_MESSAGES/main.mo
Binary file not shown.
28 changes: 14 additions & 14 deletions locales/fr_FR/LC_MESSAGES/main.po
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
msgid ""
msgstr ""
"Project-Id-Version: Flus\n"
"POT-Creation-Date: 2024-10-31 19:23+0100\n"
"PO-Revision-Date: 2024-10-31 19:23+0100\n"
"POT-Creation-Date: 2024-11-13 10:08+0100\n"
"PO-Revision-Date: 2024-11-13 10:08+0100\n"
"Last-Translator: Marien Fressinaud <dev@marienfressinaud.fr>\n"
"Language-Team: \n"
"Language: fr_FR\n"
Expand Down Expand Up @@ -60,7 +60,7 @@ msgstr "Afficher"
#: controllers/collections/Images.php:114 controllers/collections/Links.php:105
#: controllers/collections/Shares.php:98 controllers/collections/Shares.php:211
#: controllers/links/Messages.php:84 controllers/links/Repairing.php:99
#: controllers/links/Searches.php:106 controllers/my/Account.php:111
#: controllers/links/Searches.php:109 controllers/my/Account.php:111
#: controllers/my/Preferences.php:82 controllers/my/Profile.php:73
#: controllers/my/Security.php:93 controllers/my/Security.php:209
#: controllers/my/Subscription.php:74 controllers/my/Validation.php:138
Expand Down Expand Up @@ -520,12 +520,12 @@ msgstr ""
"Collectez, organisez, commentez et partagez les liens provenant de "
"l'ensemble du Web."

#: views/pages/webmanifest.json.php:23
#: views/pages/webmanifest.json.php:25
#, php-format
msgid "Bookmarks screen of %s on desktop"
msgstr "L’écran des signets de %s sur ordinateur"

#: views/pages/webmanifest.json.php:30
#: views/pages/webmanifest.json.php:32
#, php-format
msgid "Bookmarks screen of %s on mobile"
msgstr "L’écran des signets de %s sur mobile"
Expand Down Expand Up @@ -624,8 +624,8 @@ msgstr "Se déconnecter"
msgid "Search links by words or URL"
msgstr "Rechercher des liens par mots ou URL"

#: views/_layouts/connected.phtml:243 views/links/searches/show.phtml:47
#: views/links/searches/show.phtml:63
#: views/_layouts/connected.phtml:243 views/links/searches/show.phtml:55
#: views/links/searches/show.phtml:71
msgid "Search"
msgstr "Rechercher"

Expand Down Expand Up @@ -692,7 +692,7 @@ msgstr "Page suivante"
#: views/links/collections/index.phtml:43 views/links/edit.phtml:44
#: views/links/edit.phtml:73 views/links/new.phtml:42 views/links/new.phtml:59
#: views/links/new.phtml:66 views/links/repairing/new.phtml:50
#: views/links/searches/show.phtml:54 views/links/show.phtml:216
#: views/links/searches/show.phtml:62 views/links/show.phtml:216
#: views/mastodon/show.phtml:77 views/mastodon/show.phtml:132
#: views/messages/edit.phtml:44 views/my/account/deletion.phtml:63
#: views/my/preferences/edit.phtml:41 views/my/profile/edit.phtml:56
Expand Down Expand Up @@ -738,7 +738,7 @@ msgstr "Placez ici les liens que vous souhaitez consulter plus tard."

#: views/bookmarks/index.phtml:28 views/collections/_collection.phtml:31
#: views/collections/show.phtml:211 views/collections/show_public.phtml:226
#: views/links/searches/show.phtml:106 views/news/index.phtml:18
#: views/links/searches/show.phtml:114 views/news/index.phtml:18
#: views/news/index.phtml:121 views/read/index.phtml:29
#, php-format
msgid "%s link"
Expand All @@ -750,7 +750,7 @@ msgstr[1] "%s liens"
msgid "Add a link"
msgstr "Ajouter un lien"

#: views/collections/_collection.phtml:18 views/links/searches/show.phtml:101
#: views/collections/_collection.phtml:18 views/links/searches/show.phtml:109
#, php-format
msgid "Feed %s"
msgstr "Flux %s"
Expand All @@ -760,7 +760,7 @@ msgstr "Flux %s"
msgid "By %s"
msgstr "Par %s"

#: views/collections/_collection.phtml:29 views/links/searches/show.phtml:104
#: views/collections/_collection.phtml:29 views/links/searches/show.phtml:112
msgid "no links"
msgstr "aucun lien"

Expand Down Expand Up @@ -1119,12 +1119,12 @@ msgid "Change the illustration"
msgstr "Changer l’illustration"

#: views/collections/show.phtml:160 views/collections/show_public.phtml:187
#: views/links/searches/show.phtml:121
#: views/links/searches/show.phtml:129
msgid "Unfollow"
msgstr "Ne plus suivre"

#: views/collections/show.phtml:172 views/collections/show_public.phtml:198
#: views/collections/show_public.phtml:212 views/links/searches/show.phtml:130
#: views/collections/show_public.phtml:212 views/links/searches/show.phtml:138
msgid "Follow"
msgstr "Suivre"

Expand Down Expand Up @@ -1656,7 +1656,7 @@ msgid_plural "%s results (“%s”)"
msgstr[0] "%s résultat (« %s »)"
msgstr[1] "%s résultats (« %s »)"

#: views/links/searches/show.phtml:31
#: views/links/searches/show.phtml:39
msgid "What’s the address of the link or feed?"
msgstr "Quelle est l’adresse du lien ou du flux ?"

Expand Down
1 change: 1 addition & 0 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static function load(): \Minz\Router
$router->addRoute('GET', '/robots.txt', 'Pages#robots', 'robots.txt');
$router->addRoute('GET', '/app.webmanifest', 'Pages#webmanifest', 'webmanifest');
$router->addRoute('GET', '/.well-known/change-password', 'WellKnown#changePassword');
$router->addRoute('GET', '/share', 'Shares#new', 'share');

$router->addRoute('GET', '/support', 'Support#show', 'support');
$router->addRoute('POST', '/support', 'Support#create', 'call support');
Expand Down
37 changes: 37 additions & 0 deletions src/controllers/Shares.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\controllers;

use Minz\Request;
use Minz\Response;

/**
* @author Marien Fressinaud <dev@marienfressinaud.fr>
* @license http://www.gnu.org/licenses/agpl-3.0.en.html AGPL
*/
class Shares
{
/**
* Allow to share a URL to Flus.
*
* @request_param string title (ignored)
* @request_param string text
* @request_param string url
*
* @response 302 /links/search?autosubmit=1&url=<url|text>
*/
public function new(Request $request): Response
{
$url = $request->param('url', '');
$text = $request->param('text', '');

if ($url === '') {
$url = $text;
}

return Response::redirect('show search link', [
'url' => $url,
'autosubmit' => true,
]);
}
}
8 changes: 7 additions & 1 deletion src/controllers/links/Searches.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Searches
/**
* Show the page to search by URL.
*
* @request_param string id
* @request_param string url
* @request_param boolean autosubmit
*
* @response 302 /login?redirect_to=/links/search
* @response 200
Expand All @@ -36,6 +37,8 @@ public function show(Request $request): Response

$support_user = models\User::supportUser();

$autosubmit = $request->paramBoolean('autosubmit');

$url = $request->param('url', '');
$url = \SpiderBits\Url::sanitize($url);

Expand Down Expand Up @@ -69,6 +72,7 @@ public function show(Request $request): Response
'default_link' => $default_link,
'existing_link' => $existing_link,
'feeds' => $feeds,
'autosubmit' => $autosubmit,
]);
}

Expand Down Expand Up @@ -100,6 +104,7 @@ public function create(Request $request): Response
if (!\Minz\Csrf::validate($csrf)) {
return Response::badRequest('links/searches/show.phtml', [
'url' => $url,
'autosubmit' => false,
'default_link' => null,
'existing_link' => null,
'feeds' => [],
Expand All @@ -119,6 +124,7 @@ public function create(Request $request): Response
if ($errors) {
return Response::badRequest('links/searches/show.phtml', [
'url' => $url,
'autosubmit' => false,
'default_link' => null,
'existing_link' => null,
'feeds' => [],
Expand Down
10 changes: 9 additions & 1 deletion src/views/links/searches/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
<h1 id="modal-title"><?= _('New') ?></h1>
</div>

<form method="post" action="<?= url('search link') ?>">
<form
method="post"
action="<?= url('search link') ?>"
<?php if ($autosubmit): ?>
data-controller="autosubmit"
data-autosubmit-mode-value="timeout"
data-autosubmit-timeout-value="0"
<?php endif; ?>
>
<?= $this->include('alerts/_error.phtml', ['message' => $error]) ?>

<input type="hidden" name="csrf" value="<?= $csrf_token ?>" />
Expand Down
4 changes: 3 additions & 1 deletion src/views/pages/webmanifest.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"theme_color": "#00d0ad",
"share_target": {
"enctype": "application/x-www-form-urlencoded",
"action": "<?= url('show search link') ?>",
"action": "<?= url('share') ?>",
"method": "GET",
"params": {
"title": "title",
"text": "text",
"url": "url"
}
},
Expand Down
36 changes: 36 additions & 0 deletions tests/controllers/SharesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\controllers;

class SharesTest extends \PHPUnit\Framework\TestCase
{
use \Minz\Tests\ApplicationHelper;
use \Minz\Tests\InitializerHelper;
use \Minz\Tests\ResponseAsserts;
use \tests\FakerHelper;
use \tests\LoginHelper;

public function testNewRedirectosToLinkSearchWithUrl(): void
{
$url = 'https://flus.fr';

$response = $this->appRun('GET', '/share', [
'url' => $url,
]);

$encoded_url = urlencode($url);
$this->assertResponseCode($response, 302, "/links/search?url={$encoded_url}&autosubmit=1");
}

public function testNewRedirectosToLinkSearchWithText(): void
{
$url = 'https://flus.fr';

$response = $this->appRun('GET', '/share', [
'text' => $url,
]);

$encoded_url = urlencode($url);
$this->assertResponseCode($response, 302, "/links/search?url={$encoded_url}&autosubmit=1");
}
}

0 comments on commit ef66025

Please sign in to comment.