Skip to content

Commit

Permalink
Support old and new wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnyga committed Feb 8, 2021
1 parent 295608e commit 4dcce92
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions AllowedUploadsPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function register($category, $path, $mainContextId = null) {
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) return true;
if ($success && $this->getEnabled()) {

HookRegistry::register('SubmissionFile::validate', array($this, 'checkUpload'));

HookRegistry::register('SubmissionFile::validate', array($this, 'checkUploadWizard'));
HookRegistry::register('submissionfilesuploadform::validate', array($this, 'checkUpload'));
}
return $success;
}
Expand Down Expand Up @@ -101,9 +101,9 @@ function manage($args, $request) {
}

/**
* Check the uploaded file
* Check the uploaded file in wizard
*/
function checkUpload($hookName, $params) {
function checkUploadWizard($hookName, $params) {
$errors =& $params[0];
$props = $params[2];
$locale = $params[4];
Expand All @@ -124,5 +124,33 @@ function checkUpload($hookName, $params) {
}
}

/**
* Check the uploaded file
*/
function checkUpload($hookName, $params) {
$form = $params[0];
$request = Application::getRequest();
$context = $request->getContext();

$userVars = $request->getUserVars();
$fileName = $userVars['name'];
$tmp = explode('.',$fileName);
$extension = strtolower(end($tmp));

$allowedExtensions = $this->getSetting($context->getId(), 'allowedExtensions');

if ($allowedExtensions){

$allowedExtensionsArray = array_filter(array_map('trim', explode(';', $allowedExtensions )), 'strlen');

if (!in_array($extension, $allowedExtensionsArray)){
$form->addError('fileType', __('plugins.generic.allowedUploads.error', array('allowedExtensions' => $allowedExtensions)));
}

}
return false;
}


}
?>

0 comments on commit 4dcce92

Please sign in to comment.