-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Probably the last, too.
- Loading branch information
0 parents
commit 5dd65d9
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 The s9e authors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "s9e/linkshortenerer", | ||
"type": "phpbb-extension", | ||
"description": "Shortens links to this forum, or maybe not this forum but close enough.", | ||
"homepage": "https://github.com/s9e/phpbb-ext-link-shortenerer/", | ||
"version": "1.0.0", | ||
"keywords": ["phpbb"], | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=7.3.1" | ||
}, | ||
"authors": [{ "name": "JoshyPHP" }], | ||
"extra": { | ||
"display-name": "s9e/link-shortenerer", | ||
"soft-require": { | ||
"phpbb/phpbb": "3.3.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
s9e.linkshortenerer.listener: | ||
class: s9e\linkshortenerer\listener | ||
arguments: | ||
- '@config' | ||
tags: | ||
- { name: event.listener } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* @package s9e\linkshortenerer | ||
* @copyright Copyright (c) 2020 The s9e authors | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
*/ | ||
namespace s9e\linkshortenerer; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use phpbb\config\config; | ||
|
||
class listener implements EventSubscriberInterface | ||
{ | ||
protected $regexp; | ||
|
||
public function __construct(config $config) | ||
{ | ||
$this->regexp = '/^(?:\\w++:)?\\/\\/(?:[-\\w]++\\.)*' | ||
. preg_quote($config['server_name'], '/') | ||
. '(?::\\d++)?' | ||
. preg_quote(rtrim($config['script_path'], '/'), '/') | ||
. '\\//'; | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return ['core.text_formatter_s9e_configure_after' => 'onConfigure']; | ||
} | ||
|
||
public function onConfigure($event) | ||
{ | ||
if (!isset($event['configurator']->tags['LINK_TEXT'])) | ||
{ | ||
return; | ||
} | ||
|
||
$event['configurator']->tags['LINK_TEXT']->attributes['text']->filterChain | ||
->prepend('preg_replace(' . $this->regexp . ', "", $attrValue)'); | ||
} | ||
} |