ShurlyFilter.php in ShURLy 8
File
src/Plugin/Filter/ShurlyFilter.php
View source
<?php
namespace Drupal\shurly\Plugin\Filter;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
class ShurlyFilter extends FilterBase {
public function process($text, $langcode) {
preg_match_all('/<a[^>]*href="(http[^"]*)"[^>]*>/i', $text, $links);
if (!empty($links)) {
$links = $links[1];
foreach ($links as $key => $link) {
$short_url = shurly_shorten($link);
if ($short_url['success'] === TRUE) {
$text = str_replace('"' . $link . '"', '"' . $short_url['shortUrl'] . '"', $text);
}
}
}
return new FilterProcessResult($text);
}
}
Classes
Name |
Description |
ShurlyFilter |
Plugin annotation
@Filter(
id = "shurly_filter",
title = @Translation("Shorten all outgoing URL's"),
description = @Translation("All links starting with http or https will be
replaced."), type =
… |