-
Notifications
You must be signed in to change notification settings - Fork 2
/
FintoPlugin.inc.php
120 lines (105 loc) · 3.13 KB
/
FintoPlugin.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* @file fintoPlugin.inc.php
*
* Copyright (c) 2013-2021 Simon Fraser University Library
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class fintoPlugin
* @ingroup plugins_generic_finto
* @brief finto plugin class
*
*
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class FintoPlugin extends GenericPlugin {
function getName() {
return 'fintoPlugin';
}
function getDisplayName() {
return "Finto/YSO";
}
function getDescription() {
return "Integrates YSO ontology from the Finnish Finto service to the keyword field in OJS3. Supports Finnish, English and Swedish.";
}
function register($category, $path, $mainContextId = NULL) {
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
HookRegistry::register('Template::Workflow', array($this, 'addCustomAutosuggest'));
HookRegistry::register('TemplateManager::display',array($this, 'hideNativeAutosuggest'));
}
return $success;
}
/**
* Add custom js for backend and frontend
*/
function hideNativeAutosuggest($hookName, $params) {
$template =& $params[1];
if ($template !== 'workflow/workflow.tpl') {
return false;
}
$templateMgr =& $params[0];
$templateMgr->addStylesheet(
"ObjectsForReviewGridHandlerStyles",
"div[id^='metadata-keywords-autosuggest'] .autosuggest__results-container{ position: absolute; left: -9999px; }",
[
"inline" => true,
"contexts" => "backend",
]
);
return false;
}
/**
* Add YSO autoSuggest scripts for keywords
* @param $hookName string
* @param $params array
*/
function addCustomAutosuggest($hookName, $params) {
$output =& $params[2];
$output .= $this->ysoAutosuggest('en_US','en');
$output .= $this->ysoAutosuggest('fi_FI','fi');
$output .= $this->ysoAutosuggest('sv_SE','sv');
return false;
}
/**
* Get YSO autosuggest api script for selected locale
* @param $localeField string
* @param $localeApi string
* @return $string
*/
function ysoAutosuggest($localeField, $localeApi){
return "
<script>
$( function() {
$( '#metadata-keywords-control-" . $localeField . "' ).autocomplete({
source: function( request, response ) {
$.ajax( {
url: 'https://api.finto.fi/rest/v1/search?vocab=yso&lang=" . $localeApi . "',
dataType: 'json',
data: {
query: request.term + '*'
},
success:
function( data ) {
var output = data.results;
response($.map(data.results, function(item) {
return {
label: item.prefLabel + ' [' + item.uri + ']',
value: item.prefLabel + ' [' + item.uri + ']'
}
}));
}
} );
},
minLength: 2,
autoFocus: true,
select: function(){
$( '#metadata-keywords-control-" . $localeField . "' ).focus().trigger({type: 'keypress', which: 50, keyCode: 50});
}
} );
} );
</script>";
}
}
?>