From 8f5c65d53914a823a40e050fe0a96e9305ec4391 Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Fri, 23 Nov 2012 10:56:28 +1300 Subject: [PATCH] API-CHANGE: adding a method to add to the list of extensions that are allowed as Documents. --- _config.php | 4 +++- code/cms/DMSDocumentAddController.php | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/_config.php b/_config.php index 0b37808..3e67361 100644 --- a/_config.php +++ b/_config.php @@ -4,6 +4,7 @@ DMSDocument_versions::$enable_versions = true; DMSSiteTreeExtension::show_documents_tab(); //show the Documents tab on all pages DMSSiteTreeExtension::no_documents_tab(); //and don't exclude it from any pages +DMSDocumentAddController::add_allowed_extensions(); //add an array of additional allowed extensions define('DMS_DIR', 'dms'); @@ -19,4 +20,5 @@ ShortcodeParser::get('default')->register('dms_document_link', array('DMSDocumen if (DMSDocument_versions::$enable_versions) { //using the same db relations for the versioned documents, as for the actual documents Config::inst()->update('DMSDocument_versions', 'db', DMSDocument::$db); -} \ No newline at end of file +} + diff --git a/code/cms/DMSDocumentAddController.php b/code/cms/DMSDocumentAddController.php index 7a73b85..2834d9f 100644 --- a/code/cms/DMSDocumentAddController.php +++ b/code/cms/DMSDocumentAddController.php @@ -7,6 +7,18 @@ class DMSDocumentAddController extends LeftAndMain { static $required_permission_codes = 'CMS_ACCESS_AssetAdmin'; static $menu_title = 'Edit Page'; public static $tree_class = 'SiteTree'; + static $allowed_extensions = array(); + + /** + * Add an array of additional allowed extensions + * @static + * @param $array + */ + static function add_allowed_extensions($array = null) { + if (empty($array)) return; + if (is_array($array)) self::$allowed_extensions = $array; + else self::$allowed_extensions = array($array); + } /** * Custom currentPage() method to handle opening the 'root' folder @@ -59,7 +71,9 @@ class DMSDocumentAddController extends LeftAndMain { $uploadField->setTemplate('AssetUploadField'); $uploadField->setRecord($page); + $uploadField->getValidator()->setAllowedExtensions(array_filter(array_merge(File::$allowed_extensions,self::$allowed_extensions))); $exts = $uploadField->getValidator()->getAllowedExtensions(); + asort($exts); $backlink = $this->Backlink(); $done = "