Skip to content

Commit

Permalink
Support OMP
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnyga committed Mar 11, 2018
1 parent 37bfbc7 commit 545e6f4
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 33 deletions.
Binary file added .DS_Store
Binary file not shown.
21 changes: 10 additions & 11 deletions AllowedUploadsPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ function register($category, $path) {
$success = parent::register($category, $path);
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) return true;
if ($success && $this->getEnabled()) {

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

}
return $success;
}
Expand Down Expand Up @@ -105,36 +106,34 @@ function manage($args, $request) {
function getTemplatePath($inCore = false) {
return parent::getTemplatePath($inCore) . 'templates/';
}



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

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

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

$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;
}


}

?>
14 changes: 7 additions & 7 deletions AllowedUploadsSettingsForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@
* @class AllowedUploadsSettingsForm
* @ingroup plugins_generic_allowedUploads
*
* @brief Form for journal managers to modify Allowed Uploads plugin settings
* @brief Form for managers to modify Allowed Uploads plugin settings
*/

import('lib.pkp.classes.form.Form');

class AllowedUploadsSettingsForm extends Form {

/** @var int */
var $_journalId;
var $_contextId;

/** @var object */
var $_plugin;

/**
* Constructor
* @param $plugin AllowedUploadsPlugin
* @param $journalId int
* @param $contextId int
*/
function __construct($plugin, $journalId) {
$this->_journalId = $journalId;
function __construct($plugin, $contextId) {
$this->_contextId = $contextId;
$this->_plugin = $plugin;

parent::__construct($plugin->getTemplatePath() . 'settingsForm.tpl');
Expand All @@ -43,7 +43,7 @@ function __construct($plugin, $journalId) {
*/
function initData() {
$this->_data = array(
'allowedExtensions' => $this->_plugin->getSetting($this->_journalId, 'allowedExtensions'),
'allowedExtensions' => $this->_plugin->getSetting($this->_contextId, 'allowedExtensions'),
);
}

Expand All @@ -68,7 +68,7 @@ function fetch($request) {
* Save settings.
*/
function execute() {
$this->_plugin->updateSetting($this->_journalId, 'allowedExtensions', $this->getData('allowedExtensions'), 'string');
$this->_plugin->updateSetting($this->_contextId, 'allowedExtensions', $this->getData('allowedExtensions'), 'string');
}

}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ For OJS 3.1.0.1 or higher

The plugin enables the editor to choose which file extensions are allowed in their journal. NOTE! This is *not* a security plugin. Make sure that your files directory is not a subdirectory of your OJS installation. For more details read the OJS installation instructions.

Copy the plugin folder to plugins/generic/ and enable it. Edit the plugin settings and add a list semicolon separated list of allowed filetypes, for example 'doc; docx; pdf; gif; jpg;'.
Copy the plugin folder to plugins/generic/ and enable it. Edit the plugin settings and add a list semicolon separated list of allowed filetypes, for example **doc; docx; pdf; gif; jpg;**.


TODO
Expand Down
Binary file added locale/.DS_Store
Binary file not shown.
11 changes: 3 additions & 8 deletions locale/en_US/locale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@
-->

<locale name="en_US" full_name="U.S. English">

<message key="plugins.generic.allowedUploads.displayName">Allowed Uploads Plugin</message>
<message key="plugins.generic.allowedUploads.description">Allowed Uploads plugin enables journal to choose the filetypes that are allowed. NOTE! This is not a security plugin! Please make sure that the OJS files directory is outside the web root.</message>

<message key="plugins.generic.allowedUploads.error">The journal only allows submission files in following formats: {$allowedExtensions}.</message>

<message key="plugins.generic.allowedUploads.description">Allowed Uploads plugin enables journal to choose the filetypes that are allowed. NOTE! This is not a security plugin! Please make sure that the files directory is outside the web root.</message>
<message key="plugins.generic.allowedUploads.error">Only the following file extensions are allowed: {$allowedExtensions}.</message>
<message key="plugins.generic.allowedUploads.manager.settings.description">Add a semicolon separated list of allowed file extensions. For example doc; docx; pdf; gif; jpg and click OK.</message>
<message key="plugins.generic.allowedUploads.manager.settings.allowedExtensions">Allowed file extensions</message>


</locale>
</locale>
20 changes: 20 additions & 0 deletions locale/fi_FI/locale.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE locale SYSTEM "../../../../../lib/pkp/dtd/locale.dtd">

<!--
* plugins/generic/allowedUploads/locale/fi_FI/locale.xml
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* Allowed Uploads plugin localization strings
-->

<locale name="fi_FI" full_name="Suomi">
<message key="plugins.generic.allowedUploads.displayName">Sallitut tiedostomuodot -lisäosa</message>
<message key="plugins.generic.allowedUploads.description">Tämän lisäosan avulla voit rajoittaa niitä tiedostomuotoja, joita voi lähettää käsikirjoituksen yhteyteen. HUOM! Tätä lisäosaa ei ole tarkoitettu parantamaan järjestelmän tietoturvaa! Huolehdi, että järjestelmän tiedostot-hakemisto on sijoitettu tai suojattu oikein.</message>
<message key="plugins.generic.allowedUploads.error">Ainoastaan seuraavat tiedostomuodot ovat sallittuja: {$allowedExtensions}.</message>
<message key="plugins.generic.allowedUploads.manager.settings.description">Lisää puolipisteellä erotettu lista sallituista tiedostomuodoista. Esimerkiksi doc; docx; pdf; gif; jpg ja valitse OK.</message>
<message key="plugins.generic.allowedUploads.manager.settings.allowedExtensions">Sallitut tiedostomuodot</message>
</locale>
8 changes: 4 additions & 4 deletions templates/settingsForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
<script>
$(function() {ldelim}
// Attach the form handler.
$('#gaSettingsForm').pkpHandler('$.pkp.controllers.form.AjaxFormHandler');
$('#allowedUploadsSettingsForm').pkpHandler('$.pkp.controllers.form.AjaxFormHandler');
{rdelim});
</script>

<form class="pkp_form" id="gaSettingsForm" method="post" action="{url router=$smarty.const.ROUTE_COMPONENT op="manage" category="generic" plugin=$pluginName verb="settings" save=true}">
<form class="pkp_form" id="allowedUploadsSettingsForm" method="post" action="{url router=$smarty.const.ROUTE_COMPONENT op="manage" category="generic" plugin=$pluginName verb="settings" save=true}">
{csrf}
{include file="controllers/notification/inPlaceNotification.tpl" notificationId="gaSettingsFormNotification"}
{include file="controllers/notification/inPlaceNotification.tpl" notificationId="allowedUploadsSettingsFormNotification"}

<div id="description">{translate key="plugins.generic.allowedUploads.manager.settings.description"}</div>

{fbvFormArea id="webFeedSettingsFormArea"}
{fbvFormArea id="allowedUploadsSettingsFormArea"}
{fbvElement type="text" name="allowedExtensions" value=$allowedExtensions label="plugins.generic.allowedUploads.manager.settings.allowedExtensions"}
{/fbvFormArea}

Expand Down
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<version>
<application>allowedUploads</application>
<type>plugins.generic</type>
<release>1.0.0.0</release>
<date>2018-02-24</date>
<release>1.0.0.1</release>
<date>2018-03-11</date>
<lazy-load>1</lazy-load>
<class>AllowedUploadsPlugin</class>
</version>

0 comments on commit 545e6f4

Please sign in to comment.