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
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ Click a forum, topic, post or FAQ heading to copy a link to it, ready-made as BB
- Also works on the title above the posting form and on the posts in the topic review below it.
- Links are full addresses built from the forum, topic or post ID, so they work anywhere they're pasted and never carry a session ID. They always point at the forum, topic or post itself, not a page of it.
- A small icon (Font Awesome `fa-clone` by default) marks each copyable heading and turns into a tick for a moment after copying. Screen readers announce "The link has been copied."
- Built for keyboard and screen reader use: headings stay ordinary links reached with Tab and copied with Enter, each one is described as "Copy a link to this as BBCode", the icon is hidden from screen readers, and focus is always clearly outlined.
- Built for keyboard and screen reader use: headings stay ordinary links reached with Tab and copied with Enter, each one has a description matching the selected copy format, the icon is hidden from screen readers, and focus is always clearly outlined.
- Clicking a post or FAQ question also follows its anchor and keeps the link focused.
- Ctrl-, Cmd-, Shift- and middle-clicks still open the link as usual.
- When the browser won't allow copying (for example a board on plain `http://`), the BBCode is shown in a box to copy by hand.
- When the browser won't allow copying (for example a board on plain `http://`), the selected link format is shown in a box to copy by hand.
- Search engine bots get the board unchanged.
- Turn the icon on or off, or choose another icon, under **ACP → Extensions → Copy Links → Settings**.
- Choose BBCode (the default) or plain URLs, turn the icon on or off, or choose another icon, under **ACP → Extensions → Copy Links → Settings**.
- Works with prosilver and styles based on it.

## Screenshots
Expand All @@ -23,7 +24,7 @@ Click a forum, topic, post or FAQ heading to copy a link to it, ready-made as BB
<tr>
<td><a href="docs/images/screenshots/copylinks-topic.png"><img src="docs/images/screenshots/copylinks-topic.png" width="280" alt="Tick after copying a topic title"></a></td>
<td><a href="docs/images/screenshots/copylinks-faq.png"><img src="docs/images/screenshots/copylinks-faq.png" width="280" alt="Tick after copying an FAQ question"></a></td>
<td><a href="docs/images/screenshots/copylinks-acp-settings.png"><img src="docs/images/screenshots/copylinks-acp-settings.png" width="280" alt="ACP settings"></a></td>
<td><a href="docs/images/screenshots/copylinks-acp-settings.png"><img src="docs/images/screenshots/copylinks-acp-settings.png" width="280" height="197" alt="ACP settings"></a></td>
</tr>
</table>

Expand All @@ -40,6 +41,8 @@ Click an image for the full size. See the [screenshot gallery](docs/images/scree
2. In the Administration Control Panel, go to **Customise → Manage extensions**
3. Enable the **Copy Links** extension

After updating an existing installation, disable and re-enable the extension to apply the new settings migration; do not delete its data.

## Contributing

Contributions are welcome!
Expand Down
5 changes: 3 additions & 2 deletions acp/main_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
namespace phpbbmodders\copylinks\acp;

/**
* ACP settings page: whether to show an icon next to copyable headings, and
* which Font Awesome icon to use.
* ACP settings page: copy format and the icon next to copyable headings.
*/
class main_module
{
Expand Down Expand Up @@ -55,12 +54,14 @@ public function main($id, $mode)

$config->set('copylinks_icon_enable', (int) $request->variable('copylinks_icon_enable', false));
$config->set('copylinks_icon', $icon);
$config->set('copylinks_plain_url', (int) $request->variable('copylinks_plain_url', false));

$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_COPYLINKS_SETTINGS');
trigger_error($language->lang('CONFIG_UPDATED') . adm_back_link($this->u_action));
}

$template->assign_vars([
'S_COPYLINKS_PLAIN_URL' => !empty($config['copylinks_plain_url']),
'U_ACTION' => $this->u_action,
'S_COPYLINKS_ICON_ENABLE' => !empty($config['copylinks_icon_enable']),
'COPYLINKS_ICON' => !empty($config['copylinks_icon']) ? $config['copylinks_icon'] : self::DEFAULT_ICON,
Expand Down
4 changes: 4 additions & 0 deletions adm/style/acp_copylinks_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ <h1>{{ lang('ACP_COPYLINKS') }}</h1>
<form id="acp_copylinks" method="post" action="{{ U_ACTION }}">
<fieldset>
<legend>{{ lang('ACP_COPYLINKS_SETTINGS') }}</legend>
<dl>
<dt><label for="copylinks_plain_url">{{ lang('COPYLINKS_PLAIN_URL') }}{{ lang('COLON') }}</label><br><span id="copylinks_plain_url_explain">{{ lang('COPYLINKS_PLAIN_URL_EXPLAIN') }}</span></dt>
<dd><input type="checkbox" id="copylinks_plain_url" name="copylinks_plain_url" value="1" aria-describedby="copylinks_plain_url_explain"{% if S_COPYLINKS_PLAIN_URL %} checked{% endif %}></dd>
</dl>
<dl>
<dt><label for="copylinks_icon_enable">{{ lang('COPYLINKS_ICON_ENABLE') }}{{ lang('COLON') }}</label><br><span id="copylinks_icon_enable_explain">{{ lang('COPYLINKS_ICON_ENABLE_EXPLAIN') }}</span></dt>
<dd><input type="checkbox" id="copylinks_icon_enable" name="copylinks_icon_enable" value="1" aria-describedby="copylinks_icon_enable_explain"{% if S_COPYLINKS_ICON_ENABLE %} checked{% endif %}></dd>
Expand Down
4 changes: 2 additions & 2 deletions docs/images/screenshots/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Clicking a question in the FAQ copies a link to that question.

## ACP settings

**Extensions → Copy Links → Settings**: turn the icon on or off, and choose which Font Awesome icon it is. With the icon off, only the tick shows after a copy.
**Extensions → Copy Links → Settings**: choose plain URLs or BBCode (the default), turn the icon on or off, and choose which Font Awesome icon it is. With the icon off, only the tick shows after a copy.

<a href="copylinks-acp-settings.png"><img src="copylinks-acp-settings.png" width="700" alt="ACP settings"></a>
<a href="copylinks-acp-settings.png"><img src="copylinks-acp-settings.png" width="700" height="492" alt="ACP settings"></a>
Binary file modified docs/images/screenshots/copylinks-acp-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function load_language($event)
public function assign_template_vars()
{
$this->template->assign_vars([
'S_COPYLINKS_PLAIN_URL' => !empty($this->config['copylinks_plain_url']),
'U_COPYLINKS_BOARD' => generate_board_url() . '/',
'COPYLINKS_PHP_EXT' => $this->php_ext,
'COPYLINKS_ICON' => !empty($this->config['copylinks_icon_enable']) ? (string) $this->config['copylinks_icon'] : '',
Expand Down
4 changes: 3 additions & 1 deletion language/en/acp_copylinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
}

$lang = array_merge($lang, [
'ACP_COPYLINKS_SETTINGS_EXPLAIN' => 'Forum, topic, post and FAQ headings copy a link to themselves as BBCode when clicked. These settings change how those headings look.',
'COPYLINKS_PLAIN_URL' => 'Copy plain URLs',
'COPYLINKS_PLAIN_URL_EXPLAIN' => 'Copy the full address without BBCode. Leave this off to copy a BBCode link with the heading as its text.',
'ACP_COPYLINKS_SETTINGS_EXPLAIN' => 'Forum, topic, post and FAQ headings copy a link to themselves when clicked. These settings control the copied format and how those headings look.',
'COPYLINKS_ICON_ENABLE' => 'Show an icon next to copyable headings',
'COPYLINKS_ICON_ENABLE_EXPLAIN' => 'The icon shows that a heading can be copied, and turns into a tick for a moment after copying. When it is off, only the tick shows after copying.',
'COPYLINKS_ICON' => 'Icon',
Expand Down
1 change: 1 addition & 0 deletions language/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}

$lang = array_merge($lang, [
'COPYLINKS_HINT_PLAIN' => 'Copy a link to this',
'COPYLINKS_HINT' => 'Copy a link to this as BBCode',
'COPYLINKS_COPIED' => 'The link has been copied.',
'COPYLINKS_COPY_FAILED' => 'The link could not be copied automatically. Copy it from here:',
Expand Down
28 changes: 28 additions & 0 deletions migrations/add_copy_format.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Adds the copy-format setting, preserving BBCode as the default.
*
* @license GNU General Public License, version 2 (GPL-2.0)
*/

namespace phpbbmodders\copylinks\migrations;

class add_copy_format extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return isset($this->config['copylinks_plain_url']);
}

public static function depends_on()
{
return ['\\phpbbmodders\\copylinks\\migrations\\install_icon_settings'];
}

public function update_data()
{
return [
['config.add', ['copylinks_plain_url', 0]],
];
}
}
11 changes: 9 additions & 2 deletions styles/all/template/copylinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copy Links extension for the phpBB Forum Software package
*
* Turns forum, topic, post and FAQ headings into "copy link" controls. A
* click copies [url=<absolute link>]<heading text>[/url] to the clipboard.
* click copies a BBCode link or a plain URL to the clipboard.
* Links are built from IDs, so they never carry a session ID, and always point
* at the forum, topic or post itself rather than a page within it.
*
Expand All @@ -17,6 +17,7 @@
return;
}

var plainUrl = status.getAttribute('data-plain-url') === '1';
var boardUrl = status.getAttribute('data-board-url');
var phpExt = status.getAttribute('data-php-ext');
var icon = status.getAttribute('data-icon');
Expand Down Expand Up @@ -222,6 +223,12 @@
}

event.preventDefault();
copy(target, bbcodeFor(url, headingText(target)));
// Keep the activated link focused and restore same-page anchor targeting.
var fragment = target.getAttribute('href').split('#')[1];
if (fragment && document.getElementById(fragment)) {
window.location.hash = fragment;
}
target.focus({preventScroll: true});
copy(target, plainUrl ? url : bbcodeFor(url, headingText(target)));
});
})();
5 changes: 3 additions & 2 deletions styles/all/template/event/overall_footer_after.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{% if not S_IS_BOT %}
<div id="copylinks-status" class="copylinks-sr-only" role="status" aria-live="polite"
data-plain-url="{% if S_COPYLINKS_PLAIN_URL %}1{% else %}0{% endif %}"
data-board-url="{{ U_COPYLINKS_BOARD|e('html_attr') }}"
data-php-ext="{{ COPYLINKS_PHP_EXT|e('html_attr') }}"
data-icon="{{ COPYLINKS_ICON|e('html_attr') }}"
data-copied="{{ lang('COPYLINKS_COPIED')|e('html_attr') }}"
data-copy-failed="{{ lang('COPYLINKS_COPY_FAILED')|e('html_attr') }}"
data-hint="{{ lang('COPYLINKS_HINT')|e('html_attr') }}"></div>
<span id="copylinks-hint" hidden>{{ lang('COPYLINKS_HINT') }}</span>
data-hint="{{ lang(S_COPYLINKS_PLAIN_URL ? 'COPYLINKS_HINT_PLAIN' : 'COPYLINKS_HINT')|e('html_attr') }}"></div>
<span id="copylinks-hint" hidden>{{ lang(S_COPYLINKS_PLAIN_URL ? 'COPYLINKS_HINT_PLAIN' : 'COPYLINKS_HINT') }}</span>
{% INCLUDEJS '@phpbbmodders_copylinks/copylinks.js' %}
{% endif %}
Loading