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,13 @@ 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+ $ this ->addTemplateFilters ();
37+ $ this ->addToSchema ();
38+ $ this ->addFormConfig ();
39+ $ this ->addEndpoints ();
40+ $ this ->addScripts ();
41+ $ this ->addListeners ();
42+ $ this ->addHandlers ();
5043 }
5144
5245 return $ success ;
@@ -121,4 +114,74 @@ public function manage($args, $request)
121114 }
122115 return parent ::manage ($ args , $ request );
123116 }
117+
118+ public function addTemplateFilters ()
119+ {
120+ HookRegistry::register ('TemplateManager::display ' , function ($ hookName , $ args ) {
121+ $ templateMgr = $ args [0 ];
122+ $ template = $ args [1 ];
123+
124+ $ thothSectionFilter = new ThothSectionFilter ();
125+ $ thothSectionFilter ->registerFilter ($ templateMgr , $ template , $ this );
126+ });
127+ }
128+
129+ public function addToSchema ()
130+ {
131+ $ thothSchema = new ThothSchema ();
132+ HookRegistry::register ('Schema::get::submission ' , [$ thothSchema , 'addWorkIdToSchema ' ]);
133+ }
134+
135+ public function addFormConfig ()
136+ {
137+ $ publishFormConfig = new PublishFormConfig ();
138+ HookRegistry::register ('Form::config::before ' , [$ publishFormConfig , 'addConfig ' ]);
139+ }
140+
141+ public function addEndpoints ()
142+ {
143+ $ thothEndpoint = new ThothEndpoint ();
144+ HookRegistry::register ('APIHandler::endpoints ' , [$ thothEndpoint , 'addEndpoints ' ]);
145+ }
146+
147+ public function addScripts ()
148+ {
149+ HookRegistry::register ('TemplateManager::display ' , function ($ hookName , $ args ) {
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+
165+ public function addListeners ()
166+ {
167+ $ publicationPublishListener = new PublicationPublishListener ();
168+ HookRegistry::register ('Publication::validatePublish ' , [$ publicationPublishListener , 'validate ' ]);
169+ HookRegistry::register ('Publication::publish ' , [$ publicationPublishListener , 'registerThothBook ' ]);
170+
171+ $ publicationEditListener = new PublicationEditListener ();
172+ HookRegistry::register ('Publication::edit ' , [$ publicationEditListener , 'updateThothBook ' ]);
173+ }
174+
175+ public function addHandlers ()
176+ {
177+ HookRegistry::register ('LoadHandler ' , function ($ hookName , $ args ) {
178+ $ page = $ args [0 ];
179+ if ($ this ->getEnabled () && $ page === 'thoth ' ) {
180+ $ this ->import ('controllers/modal/RegisterHandler ' );
181+ define ('HANDLER_CLASS ' , 'RegisterHandler ' );
182+ return true ;
183+ }
184+ return false ;
185+ });
186+ }
124187}
0 commit comments