Move shortcode handling into a new class.

This commit is contained in:
Andrew Short 2013-10-09 20:23:50 +11:00
parent 43e925d2db
commit 2c22ff476d
3 changed files with 35 additions and 30 deletions

View File

@ -13,7 +13,9 @@ if (!file_exists(BASE_PATH . DIRECTORY_SEPARATOR . DMS_DIR)) user_error("DMS dir
CMSMenu::remove_menu_item('DMSDocumentAddController');
ShortcodeParser::get('default')->register('dms_document_link', array('DMSDocument_Controller', 'dms_link_shortcode_handler'));
ShortcodeParser::get('default')->register(
'dms_document_link', array('DMSShortcodeHandler', 'handle')
);
if ($config->get('DMSDocument_versions', 'enable_versions')) {
//using the same db relations for the versioned documents, as for the actual documents

View File

@ -916,34 +916,5 @@ class DMSDocument_Controller extends ContentController {
$this->httpError(404, 'This asset does not exist.');
}
/**
* Handles dms_document_link shortcode
* @return string
*/
public static function dms_link_shortcode_handler($arguments, $content = null, $parser = null) {
$linkText = null;
if (!empty($arguments['id'])) {
$document = DMSDocument::get()->filter(array('ID' => $arguments['id']))->First();
if ($document && !$document->isHidden()) {
if (!empty($content)) {
$linkText = sprintf('<a href="%s">%s</a>', $document->Link(), $parser->parse($content));
} else {
$linkText = $document->Link();
}
}
}
if (empty($linkText)) {
$errorPage = ErrorPage::get()->filter(array('ErrorCode' => '404'))->First();
if ($errorPage) {
$linkText = $errorPage->Link();
}
}
return $linkText;
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* Handles replacing `dms_document_link` shortcodes with links to the actual
* document.
*/
class DMSShortcodeHandler {
public static function handle($arguments, $content = null, $parser = null) {
$linkText = null;
if (!empty($arguments['id'])) {
$document = DMSDocument::get()->filter(array('ID' => $arguments['id']))->First();
if ($document && !$document->isHidden()) {
if (!empty($content)) {
$linkText = sprintf('<a href="%s">%s</a>', $document->Link(), $parser->parse($content));
} else {
$linkText = $document->Link();
}
}
}
if (empty($linkText)) {
$errorPage = ErrorPage::get()->filter(array('ErrorCode' => '404'))->First();
if ($errorPage) {
$linkText = $errorPage->Link();
}
}
return $linkText;
}
}