2013-10-09 11:23:50 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Handles replacing `dms_document_link` shortcodes with links to the actual
|
|
|
|
* document.
|
|
|
|
*/
|
|
|
|
class DMSShortcodeHandler {
|
|
|
|
|
2013-10-09 11:54:08 +02:00
|
|
|
public static function handle(
|
|
|
|
$arguments, $content, ShortcodeParser $parser, $tag, array $extra = array()
|
|
|
|
) {
|
|
|
|
if(!empty($arguments['id'])) {
|
|
|
|
$document = DMSDocument::get()->byID($arguments['id']);
|
2013-10-09 11:23:50 +02:00
|
|
|
|
2013-10-09 11:54:08 +02:00
|
|
|
if($document && !$document->isHidden()) {
|
|
|
|
if($content) {
|
|
|
|
return sprintf(
|
|
|
|
'<a href="%s">%s</a>', $document->Link(), $parser->parse($content)
|
|
|
|
);
|
2013-10-09 11:23:50 +02:00
|
|
|
} else {
|
2013-10-09 11:54:08 +02:00
|
|
|
if(isset($extra['element'])) {
|
|
|
|
$extra['element']->setAttribute('data-ext', $document->getExtension());
|
|
|
|
$extra['element']->setAttribute('data-size', $document->getFileSizeFormatted());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $document->Link();
|
2013-10-09 11:23:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-09 11:54:08 +02:00
|
|
|
$error = ErrorPage::get()->filter('ErrorCode', '404')->First();
|
|
|
|
|
|
|
|
if($error) {
|
|
|
|
return $error->Link();
|
2013-10-09 11:23:50 +02:00
|
|
|
}
|
|
|
|
|
2013-10-09 11:54:08 +02:00
|
|
|
return '';
|
2013-10-09 11:23:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|