@@ -20,7 +20,7 @@ public function register($category, $path, $mainContextId = null) {
20
20
$ success = parent ::register ($ category , $ path , $ mainContextId );
21
21
$ this ->addLocaleData ();
22
22
23
- if ($ success && Config:: getVar ( ' ithenticate ' , ' ithenticate ' ) && $ this ->getEnabled ()) {
23
+ if ($ success && $ this ->getEnabled ()) {
24
24
HookRegistry::register ('submissionsubmitstep4form::execute ' , array ($ this , 'callback ' ));
25
25
}
26
26
return $ success ;
@@ -37,25 +37,65 @@ public function getDisplayName() {
37
37
* @copydoc Plugin::getDescription()
38
38
*/
39
39
public function getDescription () {
40
- return Config:: getVar ( ' ithenticate ' , ' ithenticate ' )? __ ('plugins.generic.plagiarism.description ' ): __ ( ' plugins.generic.plagiarism.description.seeReadme ' );
40
+ return __ ('plugins.generic.plagiarism.description ' );
41
41
}
42
42
43
43
/**
44
44
* @copydoc LazyLoadPlugin::getCanEnable()
45
45
*/
46
- function getCanEnable () {
47
- if (!parent ::getCanEnable ()) return false ;
48
- return Config::getVar ('ithenticate ' , 'ithenticate ' );
46
+ function getCanEnable ($ contextId = null ) {
47
+ return !Config::getVar ('ithenticate ' , 'ithenticate ' );
48
+ }
49
+
50
+ /**
51
+ * @copydoc LazyLoadPlugin::getCanDisable()
52
+ */
53
+ function getCanDisable ($ contextId = null ) {
54
+ return !Config::getVar ('ithenticate ' , 'ithenticate ' );
49
55
}
50
56
51
57
/**
52
58
* @copydoc LazyLoadPlugin::getEnabled()
53
59
*/
54
60
function getEnabled ($ contextId = null ) {
55
- if (!parent ::getEnabled ($ contextId )) return false ;
56
- return Config::getVar ('ithenticate ' , 'ithenticate ' );
61
+ return parent ::getEnabled ($ contextId ) || Config::getVar ('ithenticate ' , 'ithenticate ' );
62
+ }
63
+
64
+ /**
65
+ * Fetch credentials from config.inc.php, if available
66
+ * @return array username and password, or null(s)
67
+ **/
68
+ function getForcedCredentials () {
69
+ $ request = Application::getRequest ();
70
+ $ context = $ request ->getContext ();
71
+ $ contextPath = $ context ->getPath ();
72
+ $ username = Config::getVar ('ithenticate ' , 'username[ ' . $ contextPath . '] ' ,
73
+ Config::getVar ('ithenticate ' , 'username ' ));
74
+ $ password = Config::getVar ('ithenticate ' , 'password[ ' . $ contextPath . '] ' ,
75
+ Config::getVar ('ithenticate ' , 'password ' ));
76
+ return [$ username , $ password ];
57
77
}
58
78
79
+ /**
80
+ * Send the editor an error message
81
+ * @param $submissionid int
82
+ * @param $message string
83
+ * @return void
84
+ **/
85
+ public function sendErrorMessage ($ submissionid , $ message ) {
86
+ $ request = Application::getRequest ();
87
+ $ context = $ request ->getContext ();
88
+ import ('classes.notification.NotificationManager ' );
89
+ $ notificationManager = new NotificationManager ();
90
+ $ roleDao = DAORegistry::getDAO ('RoleDAO ' ); /* @var $roleDao RoleDAO */
91
+ // Get the managers.
92
+ $ managers = $ roleDao ->getUsersByRoleId (ROLE_ID_MANAGER , $ context ->getId ());
93
+ while ($ manager = $ managers ->next ()) {
94
+ $ notificationManager ->createTrivialNotification ($ manager ->getId (), NOTIFICATION_TYPE_ERROR , array ('contents ' => __ ('plugins.generic.plagiarism.errorMessage ' , array ('submissionId ' => $ submissionid , 'errorMessage ' => $ message ))));
95
+ }
96
+ error_log ('iThenticate submission ' .$ submissionid .' failed: ' .$ message );
97
+ }
98
+
59
99
/**
60
100
* Send submission files to iThenticate.
61
101
* @param $hookName string
@@ -65,26 +105,35 @@ public function callback($hookName, $args) {
65
105
$ request = Application::getRequest ();
66
106
$ context = $ request ->getContext ();
67
107
$ contextPath = $ context ->getPath ();
68
- $ submissionDao = Application:: getSubmissionDAO ();
108
+ $ submissionDao = DAORegistry:: getDAO ( ' SubmissionDAO ' ); /* @var $submissionDao SubmissionDAO */
69
109
$ submission = $ submissionDao ->getById ($ request ->getUserVar ('submissionId ' ));
70
110
$ publication = $ submission ->getCurrentPublication ();
71
111
72
112
require_once (dirname (__FILE__ ) . '/vendor/autoload.php ' );
73
113
74
114
// try to get credentials for current context otherwise use default config
75
- $ username = Config::getVar ('ithenticate ' , 'username[ ' . $ contextPath . '] ' ,
76
- Config::getVar ('ithenticate ' , 'username ' ));
77
- $ password = Config::getVar ('ithenticate ' , 'password[ ' . $ contextPath . '] ' ,
78
- Config::getVar ('ithenticate ' , 'password ' ));
79
- $ ithenticate = new \bsobbe \ithenticate \Ithenticate ($ username , $ password );
115
+ $ contextId = $ context ->getId ();
116
+ list ($ username , $ password ) = $ this ->getForcedCredentials ();
117
+ if (empty ($ username ) || empty ($ password )) {
118
+ $ username = $ this ->getSetting ($ contextId , 'ithenticateUser ' );
119
+ $ password = $ this ->getSetting ($ contextId , 'ithenticatePass ' );
120
+ }
121
+
122
+ $ ithenticate = null ;
123
+ try {
124
+ $ ithenticate = new \bsobbe \ithenticate \Ithenticate ($ username , $ password );
125
+ } catch (Exception $ e ) {
126
+ $ this ->sendErrorMessage ($ submission ->getId (), $ e ->getMessage ());
127
+ return false ;
128
+ }
80
129
// Make sure there's a group list for this context, creating if necessary.
81
130
$ groupList = $ ithenticate ->fetchGroupList ();
82
131
$ contextName = $ context ->getLocalizedName ($ context ->getPrimaryLocale ());
83
132
if (!($ groupId = array_search ($ contextName , $ groupList ))) {
84
133
// No folder group found for the context; create one.
85
134
$ groupId = $ ithenticate ->createGroup ($ contextName );
86
135
if (!$ groupId ) {
87
- error_log ( 'Could not create folder group for context ' . $ contextName . ' on iThenticate. ' );
136
+ $ this -> sendErrorMessage ( $ submission -> getId (), 'Could not create folder group for context ' . $ contextName . ' on iThenticate. ' );
88
137
return false ;
89
138
}
90
139
}
@@ -97,7 +146,7 @@ public function callback($hookName, $args) {
97
146
true ,
98
147
true
99
148
))) {
100
- error_log ( 'Could not create folder for submission ID ' . $ submission ->getId () . ' on iThenticate. ' );
149
+ $ this -> sendErrorMessage ( $ submission -> getId (), 'Could not create folder for submission ID ' . $ submission ->getId () . ' on iThenticate. ' );
101
150
return false ;
102
151
}
103
152
@@ -117,12 +166,63 @@ public function callback($hookName, $args) {
117
166
Services::get ('file ' )->fs ->read ($ file ->path ),
118
167
$ folderId
119
168
)) {
120
- error_log ( 'Could not submit " ' . $ submissionFile ->getData ('path ' ) . '" to iThenticate. ' );
169
+ $ this -> sendErrorMessage ( $ submission -> getId (), 'Could not submit " ' . $ submissionFile ->getData ('path ' ) . '" to iThenticate. ' );
121
170
}
122
171
}
123
172
124
173
return false ;
125
174
}
175
+
176
+ /**
177
+ * @copydoc Plugin::getActions()
178
+ */
179
+ function getActions ($ request , $ verb ) {
180
+ $ router = $ request ->getRouter ();
181
+ import ('lib.pkp.classes.linkAction.request.AjaxModal ' );
182
+ return array_merge (
183
+ $ this ->getEnabled () ? array (
184
+ new LinkAction (
185
+ 'settings ' ,
186
+ new AjaxModal (
187
+ $ router ->url ($ request , null , null , 'manage ' , null , array ('verb ' => 'settings ' , 'plugin ' => $ this ->getName (), 'category ' => 'generic ' )),
188
+ $ this ->getDisplayName ()
189
+ ),
190
+ __ ('manager.plugins.settings ' ),
191
+ null
192
+ ),
193
+ ) : array (),
194
+ parent ::getActions ($ request , $ verb )
195
+ );
196
+ }
197
+
198
+ /**
199
+ * @copydoc Plugin::manage()
200
+ */
201
+ function manage ($ args , $ request ) {
202
+ switch ($ request ->getUserVar ('verb ' )) {
203
+ case 'settings ' :
204
+ $ context = $ request ->getContext ();
205
+
206
+ AppLocale::requireComponents (LOCALE_COMPONENT_APP_COMMON , LOCALE_COMPONENT_PKP_MANAGER );
207
+ $ templateMgr = TemplateManager::getManager ($ request );
208
+ $ templateMgr ->registerPlugin ('function ' , 'plugin_url ' , array ($ this , 'smartyPluginUrl ' ));
209
+
210
+ $ this ->import ('PlagiarismSettingsForm ' );
211
+ $ form = new PlagiarismSettingsForm ($ this , $ context ->getId ());
212
+
213
+ if ($ request ->getUserVar ('save ' )) {
214
+ $ form ->readInputData ();
215
+ if ($ form ->validate ()) {
216
+ $ form ->execute ();
217
+ return new JSONMessage (true );
218
+ }
219
+ } else {
220
+ $ form ->initData ();
221
+ }
222
+ return new JSONMessage (true , $ form ->fetch ($ request ));
223
+ }
224
+ return parent ::manage ($ args , $ request );
225
+ }
126
226
}
127
227
128
228
/**
0 commit comments