enhancePostContent/src/Filter/EpcFilterTwitter.php

56 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2022-12-21 21:27:20 +00:00
<?php
2023-10-11 19:02:43 +00:00
2023-04-09 08:17:36 +00:00
declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter;
2022-12-21 21:27:20 +00:00
2023-04-09 08:17:36 +00:00
use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter;
2023-10-11 19:02:43 +00:00
/**
* @brief enhancePostContent twitter filter.
* @ingroup enhancePostContent
*
* @author Jean-Christian Denis
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2023-04-09 08:17:36 +00:00
class EpcFilterTwitter extends EpcFilter
2022-12-21 21:27:20 +00:00
{
protected string $id = 'twitter';
protected function initProperties(): array
2022-12-21 21:27:20 +00:00
{
return [
2023-04-21 22:21:30 +00:00
'priority' => 1000,
'name' => __('Twitter'),
'description' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'),
'ingore' => ['pre','code','a'],
'class' => ['a.epc-twitter'],
'replace' => '<a class="epc-twitter" title="' . __("View this user's twitter page") . '" href="%s">%s</a>',
];
}
2022-12-21 21:27:20 +00:00
protected function initSettings(): array
{
return [
2023-04-21 22:21:30 +00:00
'style' => ['text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'],
'notag' => ['h1','h2','h3'],
'template' => ['EntryContent'],
'page' => ['post.html'],
];
2022-12-21 21:27:20 +00:00
}
2023-04-09 08:17:36 +00:00
public function publicContent(string $tag, array $args): void
2022-12-21 21:27:20 +00:00
{
2023-04-09 08:17:36 +00:00
$args[0] = Epc::replaceString(
2022-12-21 21:27:20 +00:00
'[A-Za-z0-9_]{2,}',
sprintf($this->replace, 'http://twitter.com/\\1', '\\1'),
$args[0],
$this,
'[^@]@',
'\b'
);
}
}