Skip to content

Commit

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

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

}
return $success;
Expand Down Expand Up @@ -103,28 +103,25 @@ function manage($args, $request) {
/**
* Check the uploaded file
*/
function checkUpload($hookName, $params) {
$form = $params[0];
function checkUpload($hookName, $params) {
$errors =& $params[0];
$props = $params[2];
$locale = $params[4];
$request = Application::getRequest();
$context = $request->getContext();

$userVars = $request->getUserVars();
$fileName = $userVars['name'];
$fileName = $props['name'][$locale];
$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)));
$errors['allowedExtensions'][$locale] = __('plugins.generic.allowedUploads.error', array('allowedExtensions' => $allowedExtensions));
}

}
return false;
}

}
Expand Down

0 comments on commit 295608e

Please sign in to comment.