silverstripe-dms/code/DMSShortcodeHandler.php

43 lines
1.1 KiB
PHP
Raw Normal View History

<?php
/**
* Handles replacing `dms_document_link` shortcodes with links to the actual
* document.
*
* @package dms
*/
2015-12-17 19:48:37 +01:00
class DMSShortcodeHandler
{
public static function handle($arguments, $content, ShortcodeParser $parser, $tag, array $extra = array())
{
2015-12-17 19:48:37 +01:00
if (!empty($arguments['id'])) {
$document = DMSDocument::get()->byID($arguments['id']);
if ($document && !$document->isHidden()) {
if ($content) {
return sprintf(
'<a href="%s">%s</a>',
$document->Link(),
$parser->parse($content)
2015-12-17 19:48:37 +01:00
);
}
2015-12-17 19:48:37 +01:00
if (isset($extra['element'])) {
$extra['element']->setAttribute('data-ext', $document->getExtension());
$extra['element']->setAttribute('data-size', $document->getFileSizeFormatted());
2015-12-17 19:48:37 +01:00
}
return $document->Link();
2015-12-17 19:48:37 +01:00
}
}
$error = ErrorPage::get()->filter('ErrorCode', '404')->First();
if ($error) {
return $error->Link();
}
return '';
}
}