You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
namespace Isekai\Widgets;
|
|
|
|
use Html;
|
|
|
|
class ExtraFontWidget {
|
|
public static function create($text, $params, \Parser $parser, \PPFrame $frame){
|
|
$existsFonts = $parser->extIsekaiWidgetsCache->get('extraFonts', INF, []);
|
|
|
|
$content = $text = $parser->recursiveTagParse($text, $frame);
|
|
if (empty($params['name'])) {
|
|
return '<span class="error">' . wfMessage('isekai-font-error-invalid-params')->parse() . '</span>' . $content;
|
|
}
|
|
|
|
$fontName = 'extra-' . $params['name'];
|
|
if (preg_match('/[`~!@#$%^&*()+=<>?:"{}|,.\/;\'\\\\\[\]]\r\n/', $fontName)) {
|
|
return '<span class="error">' .
|
|
wfMessage('isekai-font-error-font-name-invalid')->parse() .
|
|
'</span>' .
|
|
$content;
|
|
}
|
|
|
|
$existsFonts = $parser->extIsekaiWidgetsCache->get('extraFonts', INF, []);
|
|
if (!isset($existsFonts[$fontName])) {
|
|
return '<span class="error">' .
|
|
wfMessage('isekai-font-error-font-not-imported', $params['name'])->parse() .
|
|
'</span>' .
|
|
$content;
|
|
}
|
|
$fontId = $existsFonts[$fontName];
|
|
|
|
return [
|
|
Html::rawElement('span', [
|
|
'class' => 'isekai-extra-font font-' . $fontId,
|
|
], $content),
|
|
"markerType" => 'nowiki'
|
|
];
|
|
}
|
|
} |