55 *
66 * Copyright (c) 2014-2020 Simon Fraser University
77 * Copyright (c) 2003-2020 John Willinsky
8- * Copyright (c) 2024 Lepidus Tecnologia
9- * Copyright (c) 2024 Thoth
8+ * Copyright (c) 2024-2025 Lepidus Tecnologia
9+ * Copyright (c) 2024-2025 Thoth
1010 * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
1111 *
1212 * @class ThothPlugin
1818require_once (__DIR__ . '/vendor/autoload.php ' );
1919
2020import ('lib.pkp.classes.plugins.GenericPlugin ' );
21- import ('plugins.generic.thoth.classes.ThothBadgeRender ' );
22- import ('plugins.generic.thoth.classes.ThothNotification ' );
23- import ('plugins.generic.thoth.classes.ThothRegister ' );
24- import ('plugins.generic.thoth.classes.ThothUpdater ' );
21+ import ('plugins.generic.thoth.classes.api.ThothEndpoint ' );
22+ import ('plugins.generic.thoth.classes.components.forms.config.PublishFormConfig ' );
23+ import ('plugins.generic.thoth.classes.filters.ThothSectionFilter ' );
24+ import ('plugins.generic.thoth.classes.listeners.PublicationEditListener ' );
25+ import ('plugins.generic.thoth.classes.listeners.PublicationPublishListener ' );
26+ import ('plugins.generic.thoth.classes.notification.ThothNotification ' );
27+ import ('plugins.generic.thoth.classes.schema.ThothSchema ' );
2528
2629class ThothPlugin extends GenericPlugin
2730{
@@ -30,23 +33,15 @@ public function register($category, $path, $mainContextId = null)
3033 $ success = parent ::register ($ category , $ path );
3134
3235 if ($ success && $ this ->getEnabled ()) {
33- $ thothRegister = new ThothRegister ($ this );
34- HookRegistry::register ('Schema::get::submission ' , [$ thothRegister , 'addWorkIdToSchema ' ]);
35- HookRegistry::register ('Form::config::before ' , [$ thothRegister , 'addThothField ' ]);
36- HookRegistry::register ('Publication::validatePublish ' , [$ thothRegister , 'validateRegister ' ]);
37- HookRegistry::register ('TemplateManager::display ' , [$ thothRegister , 'addResources ' ]);
38- HookRegistry::register ('Publication::publish ' , [$ thothRegister , 'registerOnPublish ' ]);
39- HookRegistry::register ('LoadHandler ' , [$ thothRegister , 'setupHandler ' ]);
40- HookRegistry::register ('APIHandler::endpoints ' , [$ thothRegister , 'addThothEndpoint ' ]);
41-
42- $ thothUpdater = new ThothUpdater ($ this );
43- HookRegistry::register ('Publication::edit ' , [$ thothUpdater , 'updateWork ' ]);
44-
45- $ thothBadgeRender = new ThothBadgeRender ($ this );
46- HookRegistry::register ('TemplateManager::display ' , [$ thothBadgeRender , 'addThothBadge ' ]);
47-
48- $ thothNotification = new ThothNotification ($ this );
49- HookRegistry::register ('TemplateManager::display ' , [$ thothNotification , 'addNotificationScript ' ]);
36+ HookRegistry::register ('TemplateManager::display ' , [$ this , 'addScripts ' ]);
37+ HookRegistry::register ('TemplateManager::display ' , [$ this , 'addTemplateFilters ' ]);
38+ HookRegistry::register ('TemplateManager::display ' , [$ this , 'addMenu ' ]);
39+ HookRegistry::register ('LoadHandler ' , [$ this , 'addHandlers ' ]);
40+
41+ $ this ->addToSchema ();
42+ $ this ->addFormConfig ();
43+ $ this ->addEndpoints ();
44+ $ this ->addListeners ();
5045 }
5146
5247 return $ success ;
@@ -121,4 +116,111 @@ public function manage($args, $request)
121116 }
122117 return parent ::manage ($ args , $ request );
123118 }
119+
120+ public function addTemplateFilters ($ hookName , $ args )
121+ {
122+ $ templateMgr = $ args [0 ];
123+ $ template = $ args [1 ];
124+
125+ $ thothSectionFilter = new ThothSectionFilter ();
126+ $ thothSectionFilter ->registerFilter ($ templateMgr , $ template , $ this );
127+ }
128+
129+ public function addToSchema ()
130+ {
131+ $ thothSchema = new ThothSchema ();
132+ HookRegistry::register ('Schema::get::submission ' , [$ thothSchema , 'addWorkIdToSchema ' ]);
133+ HookRegistry::register ('Submission::getBackendListProperties::properties ' , [$ thothSchema , 'addToBackendProps ' ]);
134+ }
135+
136+ public function addFormConfig ()
137+ {
138+ $ publishFormConfig = new PublishFormConfig ();
139+ HookRegistry::register ('Form::config::before ' , [$ publishFormConfig , 'addConfig ' ]);
140+ }
141+
142+ public function addEndpoints ()
143+ {
144+ $ thothEndpoint = new ThothEndpoint ();
145+ HookRegistry::register ('APIHandler::endpoints ' , [$ thothEndpoint , 'addEndpoints ' ]);
146+ }
147+
148+ public function addScripts ($ hookName , $ args )
149+ {
150+ $ templateMgr = $ args [0 ];
151+ $ template = $ args [1 ];
152+ $ request = Application::get ()->getRequest ();
153+
154+ $ thothNotification = new ThothNotification ();
155+ $ thothNotification ->addJavaScriptData ($ request , $ templateMgr );
156+ $ thothNotification ->addJavaScript ($ request , $ templateMgr , $ this );
157+
158+ $ thothSectionFilter = new ThothSectionFilter ();
159+ $ thothSectionFilter ->addJavaScriptData ($ request , $ templateMgr , $ template );
160+ $ thothSectionFilter ->addJavaScript ($ request , $ templateMgr , $ this );
161+ $ thothSectionFilter ->addStyleSheet ($ request , $ templateMgr , $ this );
162+ }
163+
164+ public function addListeners ()
165+ {
166+ $ publicationPublishListener = new PublicationPublishListener ();
167+ HookRegistry::register ('Publication::validatePublish ' , [$ publicationPublishListener , 'validate ' ]);
168+ HookRegistry::register ('Publication::publish ' , [$ publicationPublishListener , 'registerThothBook ' ]);
169+
170+ $ publicationEditListener = new PublicationEditListener ();
171+ HookRegistry::register ('Publication::edit ' , [$ publicationEditListener , 'updateThothBook ' ]);
172+ }
173+
174+ public function addHandlers ($ hookName , $ args )
175+ {
176+ $ page = $ args [0 ];
177+ $ op = $ args [1 ];
178+
179+ if (!$ this ->getEnabled () || $ page !== 'thoth ' ) {
180+ return false ;
181+ }
182+
183+ if ($ op === 'register ' ) {
184+ $ this ->import ('controllers/modal/RegisterHandler ' );
185+ define ('HANDLER_CLASS ' , 'RegisterHandler ' );
186+ return true ;
187+ }
188+
189+ if ($ op === 'index ' ) {
190+ $ this ->import ('pages/thoth/ThothHandler ' );
191+ define ('HANDLER_CLASS ' , 'ThothHandler ' );
192+ return true ;
193+ }
194+
195+ return false ;
196+ }
197+
198+ public function addMenu ($ hookName , $ args )
199+ {
200+ $ templateMgr = $ args [0 ];
201+
202+ $ request = Application::get ()->getRequest ();
203+ $ router = $ request ->getRouter ();
204+ $ userRoles = (array ) $ router ->getHandler ()->getAuthorizedContextObject (ASSOC_TYPE_USER_ROLES );
205+
206+ $ menu = $ templateMgr ->getState ('menu ' );
207+
208+ if (empty ($ menu )) {
209+ return false ;
210+ }
211+
212+ if (in_array (ROLE_ID_MANAGER , $ userRoles )) {
213+ $ menu = array_slice ($ menu , 0 , 2 , true ) +
214+ [
215+ 'thoth ' => [
216+ 'name ' => __ ('plugins.generic.thoth.navigation.thoth ' ),
217+ 'url ' => $ router ->url ($ request , null , 'thoth ' ),
218+ 'isCurrent ' => $ router ->getRequestedPage ($ request ) === 'thoth ' ,
219+ ]
220+ ] +
221+ array_slice ($ menu , 2 , null , true );
222+ }
223+
224+ $ templateMgr ->setState (['menu ' => $ menu ]);
225+ }
124226}
0 commit comments