Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Probably the last, too.
  • Loading branch information
JoshyPHP committed Feb 13, 2020
0 parents commit 5dd65d9
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE
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.
19 changes: 19 additions & 0 deletions s9e/linkshortenerer/composer.json
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"
}
}
}
7 changes: 7 additions & 0 deletions s9e/linkshortenerer/config/services.yml
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 }
41 changes: 41 additions & 0 deletions s9e/linkshortenerer/listener.php
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)');
}
}

0 comments on commit 5dd65d9

Please sign in to comment.