From 2c22ff476db4e988152ab3be59f0c59b9e01b4c4 Mon Sep 17 00:00:00 2001 From: Andrew Short Date: Wed, 9 Oct 2013 20:23:50 +1100 Subject: [PATCH] Move shortcode handling into a new class. --- _config.php | 4 +++- code/DMSDocument.php | 29 ----------------------------- code/DMSShortcodeHandler.php | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 code/DMSShortcodeHandler.php diff --git a/_config.php b/_config.php index 1703523..a1eaa70 100644 --- a/_config.php +++ b/_config.php @@ -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 diff --git a/code/DMSDocument.php b/code/DMSDocument.php index 9eb3be8..83eaf61 100755 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -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('%s', $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; - } - } diff --git a/code/DMSShortcodeHandler.php b/code/DMSShortcodeHandler.php new file mode 100644 index 0000000..452814f --- /dev/null +++ b/code/DMSShortcodeHandler.php @@ -0,0 +1,32 @@ +filter(array('ID' => $arguments['id']))->First(); + if ($document && !$document->isHidden()) { + if (!empty($content)) { + $linkText = sprintf('%s', $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; + } + +}