Commit 75f628ea authored by Emma's avatar Emma

setting to open link in new tab (submissions only)

parent 5f5f6552
......@@ -183,6 +183,13 @@ class User implements UserInterface {
*/
private $frontPage = self::FRONT_DEFAULT;
/**
* @ORM\Column(type="boolean", options={"default": false})
*
* @var bool
*/
private $openExternalLinksInNewTab = false;
public function __construct(string $username, string $password, \DateTime $created = null) {
$this->setUsername($username);
$this->password = $password;
......@@ -494,6 +501,14 @@ class User implements UserInterface {
$this->frontPage = $frontPage;
}
public function openExternalLinksInNewTab(): bool {
return $this->openExternalLinksInNewTab;
}
public function setOpenExternalLinksInNewTab(bool $openExternalLinksInNewTab) {
$this->openExternalLinksInNewTab = $openExternalLinksInNewTab;
}
/**
* Returns the canonical form of the username.
*
......
......@@ -65,6 +65,8 @@ class UserData implements UserInterface {
*/
private $preferredTheme;
private $openExternalLinksInNewTab;
public static function fromUser(User $user): UserData {
$self = new self();
$self->entityId = $user->getId();
......@@ -75,6 +77,7 @@ class UserData implements UserInterface {
$self->nightMode = $user->isNightMode();
$self->showCustomStylesheets = $user->isShowCustomStylesheets();
$self->preferredTheme = $user->getPreferredTheme();
$self->openExternalLinksInNewTab = $user->openExternalLinksInNewTab();
return $self;
}
......@@ -92,6 +95,7 @@ class UserData implements UserInterface {
$user->setNightMode($this->nightMode);
$user->setShowCustomStylesheets($this->showCustomStylesheets);
$user->setPreferredTheme($this->preferredTheme);
$user->setOpenExternalLinksInNewTab($this->openExternalLinksInNewTab);
}
public function toUser(): User {
......@@ -103,7 +107,8 @@ class UserData implements UserInterface {
'frontPage',
'locale',
'nightMode',
'preferredTheme'
'preferredTheme',
'openExternalLinksInNewTab',
];
foreach ($settings as $setting) {
......@@ -199,6 +204,14 @@ class UserData implements UserInterface {
$this->preferredTheme = $preferredTheme;
}
public function openExternalLinksInNewTab() {
return $this->openExternalLinksInNewTab;
}
public function setOpenExternalLinksInNewTab($openExternalLinksInNewTab) {
$this->openExternalLinksInNewTab = $openExternalLinksInNewTab;
}
/**
* {@inheritdoc}
*/
......
......@@ -49,6 +49,10 @@ final class UserSettingsType extends AbstractType {
'placeholder' => 'placeholder.default',
'required' => false,
])
->add('openExternalLinksInNewTab', CheckboxType::class, [
'required' => false,
'label' => 'label.open_external_links_in_new_tab',
])
->add('save', SubmitType::class);
}
......
<?php
namespace DoctrineMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
class Version20171015195433 extends AbstractMigration {
/**
* @param Schema $schema
*/
public function up(Schema $schema) {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE users ADD open_external_links_in_new_tab BOOLEAN DEFAULT FALSE NOT NULL');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema) {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE users DROP open_external_links_in_new_tab');
}
}
......@@ -50,6 +50,7 @@
{%- block submission -%}
{%- from 'vote/_macros.html.twig' import vote -%}
{%- set open_external = submission.url is not empty and (app.user.openExternalLinksInNewTab ?? false) -%}
<article class="submission {{ submission.url ? 'submission-has-url' }} {{ submission.body is not null ? 'submission-has-body' }} {{ not options.show_body ? 'submission-body-hidden' }} {{ submission.sticky ? 'submission-sticky' }} {{ submission.locked ? 'submission-locked' }}">
<div class="submission-row">
<div class="submission-vote">
......@@ -58,7 +59,7 @@
{% if submission.image %}
<div class="submission-image-container">
<a href="{{ block('submission_url') }}" class="submission-image">
<a href="{{ block('submission_url') }}" class="submission-image" {% if submission.url %}rel="nofollow noreferrer noopener" target="{{ open_external ? '_blank' }}"{% endif %}>
<img src="{{ submission.image|imagine_filter('submission_thumbnail') }}" class="submission-thumbnail" alt="">
</a>
</div>
......@@ -67,7 +68,7 @@
<div class="submission-inner">
<header class="submission-header">
<h1 class="submission-title">
<a href="{{ block('submission_url') }}" class="submission-link">
<a href="{{ block('submission_url') }}" class="submission-link" {% if submission.url %}rel="nofollow noreferrer noopener" target="{{ open_external ? '_blank' }}"{% endif %}>
{{- submission.title -}}
</a>
......
......@@ -14,6 +14,8 @@
{{ form_row(form.locale) }}
{{ form_row(form.front_page) }}
{{ form_row(form.openExternalLinksInNewTab) }}
</fieldset>
<fieldset class="form__group">
......
......@@ -235,6 +235,7 @@ label:
admin: Admin
bans: Bans
overview: Overview
open_external_links_in_new_tab: Open external links in new tab
login_form:
log_in: Log in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment