From 6d0af08f1a5c875185179a1266921294be384523 Mon Sep 17 00:00:00 2001 From: Stephen Shkardoon Date: Fri, 23 Aug 2013 01:09:06 +1200 Subject: [PATCH] Fix #14 - Shortcode download link fixed --- code/DMSDocument.php | 21 ++++++++++---------- javascript/DocumentHtmlEditorFieldToolbar.js | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/code/DMSDocument.php b/code/DMSDocument.php index 35e3e32..b6f8228 100755 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -923,24 +923,25 @@ class DMSDocument_Controller extends Controller { */ public static function dms_link_shortcode_handler($arguments, $content = null, $parser = null) { $linkText = null; - if(isset($arguments['id']) && is_numeric($arguments['id'])) { - // get the document object - $document = DataObject::get_by_id('DMSDocument', Convert::raw2sql($arguments['id'])); + + if (!empty($arguments['id'])) { + $document = DMSDocument::get()->filter(array('ID' => $arguments['id']))->First(); if ($document && !$document->isHidden()) { - if( $content ) { + if (!empty($content)) { $linkText = sprintf('%s', $document->Link(), $parser->parse($content)); } else { - $extension = $document->getExtension(); - $size = "data:{size:'{$document->getFileSizeFormatted()}'}"; - $linkText = $document->getLink()."\" class=\"$size documentLink $extension"; + $linkText = $document->Link(); } } } - if (!$linkText) { - $errorPage = DataObject::get_one('ErrorPage', '"ErrorCode" = \'404\''); - if ($errorPage) $linkText = $errorPage->Link(); + if (empty($linkText)) { + $errorPage = ErrorPage::get()->filter(array('ErrorCode' => '404'))->First(); + if ($errorPage) { + $linkText = $errorPage->Link(); + } } + return $linkText; } diff --git a/javascript/DocumentHtmlEditorFieldToolbar.js b/javascript/DocumentHtmlEditorFieldToolbar.js index c73a59f..495ffee 100644 --- a/javascript/DocumentHtmlEditorFieldToolbar.js +++ b/javascript/DocumentHtmlEditorFieldToolbar.js @@ -41,6 +41,7 @@ var attributes = { href : href, target : target, + class : 'documentLink', title : this.find('.selected-document').text() //title is the text of the selected document }; @@ -104,4 +105,4 @@ }); }); -}(jQuery)); \ No newline at end of file +}(jQuery));