Skip to content

Commit

Permalink
moved CDN setting from config.inc.php to plugin settings (setting got…
Browse files Browse the repository at this point in the history
… deprecated in OJS 3.3 in the config.inc.php)
  • Loading branch information
tnier01 committed Feb 18, 2021
1 parent ef9c905 commit e49470e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The plugin was developed as part of a bachelor thesis. This thesis can be found
- insert the folder ```geoOJS``` in the path ```ojs/plugins/generic/``` in OJS
- activate the plugin geoOJS in the OJS plug-in settings
- Specify your geonames username
- If you want to disable CDN you can do it [here](https://github.com/tnier01/geoOJS/wiki/Enable-CDN)

# Specify geonames username
- You have to specify your username for the geonames api, so that an alignment for the administrative units is possible.
Expand All @@ -68,6 +69,6 @@ Further information you find in the [Wiki](https://github.com/tnier01/geoOJS/wik

**Wiki Content**
* [geoJSON-Specification](https://github.com/tnier01/geoOJS/wiki/geoJSON-Specification)
* [Enable CDN](https://github.com/tnier01/geoOJS/wiki/Enable-CDN)
* [Disable CDN](https://github.com/tnier01/geoOJS/wiki/Enable-CDN)


13 changes: 10 additions & 3 deletions geoOJSPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ public function register($category, $path, $mainContextId = NULL)
$templateMgr = TemplateManager::getManager($request);

/*
To respect the enable_cdn configuration setting. When this is off,
plugins should not load any scripts or styles from a third-party website.
In previous OJS versions, there was an option in the config.inc.php to enable or disable CDN.
As it was deprecated in OJS 3.3, we decide it to integrate it by a plugin setting: checkboxDisableCDN.
If the checkbox is checked the variable $checkboxDisableCDN is = "on" , CDN is disabled. Thus the plugins should not load any scripts or styles from a third-party website.
Old configuration option which is disabled: Config::getVar('general', 'enable_cdn').
*/
if (Config::getVar('general', 'enable_cdn')) {
$request = Application::get()->getRequest();
$context = $request->getContext();
$checkboxDisableCDN = $this->getSetting($context->getId(), 'checkboxDisableCDN');

if ($checkboxDisableCDN !== "on") {
// if the user allows CDN
$urlLeafletCSS = 'https://unpkg.com/leaflet@1.6.0/dist/leaflet.css';
$urlLeafletJS = 'https://unpkg.com/leaflet@1.6.0/dist/leaflet.js';
$urlLeafletDrawCSS = 'https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css';
Expand Down
3 changes: 3 additions & 0 deletions geoOJSPluginSettingsForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function initData()
{
$contextId = Application::get()->getRequest()->getContext()->getId();
$this->setData('usernameGeonames', $this->plugin->getSetting($contextId, 'usernameGeonames'));
$this->setData('checkboxDisableCDN', $this->plugin->getSetting($contextId, 'checkboxDisableCDN'));
parent::initData();
}

Expand All @@ -39,6 +40,7 @@ public function initData()
public function readInputData()
{
$this->readUserVars(['usernameGeonames']);
$this->readUserVars(['checkboxDisableCDN']);
parent::readInputData();
}

Expand Down Expand Up @@ -67,6 +69,7 @@ public function execute()
{
$contextId = Application::get()->getRequest()->getContext()->getId();
$this->plugin->updateSetting($contextId, 'usernameGeonames', $this->getData('usernameGeonames'));
$this->plugin->updateSetting($contextId, 'checkboxDisableCDN', $this->getData('checkboxDisableCDN'));

// Tell the user that the save was successful.
import('classes.notification.NotificationManager');
Expand Down
5 changes: 5 additions & 0 deletions locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ msgstr "username for https://www.geonames.org/login"
msgid "plugins.generic.geoOJS.settings.usernameGeonames.description"
msgstr "You have to specify your username for the geonames api, so that an alignment for the administrative units is possible. Create a account on https://www.geonames.org/login and insert the username here!"

msgid "plugins.generic.geoOJS.settings.CDN"
msgstr "Disable CDN"

msgid "plugins.generic.geoOJS.settings.CDN.description"
msgstr "You have to specify if you want CDN to be enabled or not. If the checkbox is checked, CDN is disabled. By default CDN is enabled."

14 changes: 12 additions & 2 deletions templates/settings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{csrf}

{fbvFormArea}
{fbvFormSection}
{fbvFormSection list=true}
<p align="justify" class="description" style="color: rgba(0,0,0,0.54)">{translate
key="plugins.generic.geoOJS.settings.usernameGeonames.description"}
{fbvElement
Expand All @@ -21,6 +21,16 @@
label="plugins.generic.geoOJS.settings.usernameGeonames"
}
{/fbvFormSection}
{fbvFormSection list=true}
<p align="justify" class="description" style="color: rgba(0,0,0,0.54)"> {translate
key="plugins.generic.geoOJS.settings.CDN.description"}
{fbvElement
type="checkbox"
id="checkboxDisableCDN"
checked=$checkboxDisableCDN
label="plugins.generic.geoOJS.settings.CDN"
}
{/fbvFormSection}
{/fbvFormArea}
{fbvFormButtons submitText="common.save"}
</form>
</form>

0 comments on commit e49470e

Please sign in to comment.