3
3
/**
4
4
* @file plugins/themes/default/DefaultThemePlugin.php
5
5
*
6
- * Copyright (c) 2014-2022 Simon Fraser University
7
- * Copyright (c) 2003-2022 John Willinsky
6
+ * Copyright (c) 2014-2021 Simon Fraser University
7
+ * Copyright (c) 2003-2021 John Willinsky
8
8
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
9
9
*
10
10
* @class DefaultThemePlugin
17
17
use APP \core \Application ;
18
18
use APP \file \PublicFileManager ;
19
19
use PKP \config \Config ;
20
- use PKP \plugins \ThemePlugin ;
21
20
use PKP \session \SessionManager ;
22
21
23
- class DefaultThemePlugin extends ThemePlugin
22
+ use APP \facades \Repo ;
23
+ use APP \issue \Collector ;
24
+ use APP \services \NavigationMenuService ;
25
+ use PKP \plugins \ThemePlugin ;
26
+ use PKP \plugins \Hook ;
27
+
28
+
29
+ class DefaultThemePlugin extends \PKP \plugins \ThemePlugin
24
30
{
25
31
/**
26
32
* @copydoc ThemePlugin::isActive()
@@ -77,35 +83,34 @@ public function init()
77
83
],
78
84
'default ' => 'notoSans ' ,
79
85
]);
80
- $ this ->addOption ('useHomepageImageAsHeader ' , 'FieldOptions ' , [
81
- 'label ' => __ ('plugins.themes.default.option.useHomepageImageAsHeader.label ' ),
82
- 'description ' => __ ('plugins.themes.default.option.useHomepageImageAsHeader.description ' ),
83
- 'options ' => [
84
- [
85
- 'value ' => true ,
86
- 'label ' => __ ('plugins.themes.default.option.useHomepageImageAsHeader.option ' )
87
- ],
88
- ],
89
- 'default ' => false ,
90
- ]);
91
86
92
87
$ this ->addOption ('baseColour ' , 'FieldColor ' , [
93
88
'label ' => __ ('plugins.themes.default.option.colour.label ' ),
94
89
'description ' => __ ('plugins.themes.default.option.colour.description ' ),
95
90
'default ' => '#1E6292 ' ,
96
91
]);
97
92
98
- $ this ->addOption ('showCatalogSeriesListing ' , 'FieldOptions ' , [
99
- 'label ' => __ ('plugins.themes.default.option.showCatalogSeriesListing.label ' ),
93
+ $ this ->addOption ('showDescriptionInJournalIndex ' , 'FieldOptions ' , [
94
+ 'label ' => __ ('manager.setup.contextSummary ' ),
100
95
'options ' => [
101
96
[
102
97
'value ' => true ,
103
- 'label ' => __ ('plugins.themes.default.option.showCatalogSeriesListing.option ' )
98
+ 'label ' => __ ('plugins.themes.default.option.showDescriptionInJournalIndex.option ' ),
99
+ ],
100
+ ],
101
+ 'default ' => false ,
102
+ ]);
103
+ $ this ->addOption ('useHomepageImageAsHeader ' , 'FieldOptions ' , [
104
+ 'label ' => __ ('plugins.themes.default.option.useHomepageImageAsHeader.label ' ),
105
+ 'description ' => __ ('plugins.themes.default.option.useHomepageImageAsHeader.description ' ),
106
+ 'options ' => [
107
+ [
108
+ 'value ' => true ,
109
+ 'label ' => __ ('plugins.themes.default.option.useHomepageImageAsHeader.option ' )
104
110
],
105
111
],
106
112
'default ' => false ,
107
113
]);
108
-
109
114
$ this ->addOption ('displayStats ' , 'FieldOptions ' , [
110
115
'type ' => 'radio ' ,
111
116
'label ' => __ ('plugins.themes.default.option.displayStats.label ' ),
@@ -126,6 +131,7 @@ public function init()
126
131
'default ' => 'none ' ,
127
132
]);
128
133
134
+
129
135
// Load primary stylesheet
130
136
$ this ->addStyle ('stylesheet ' , 'styles/index.less ' );
131
137
@@ -211,10 +217,13 @@ public function init()
211
217
212
218
// Add navigation menu areas for this theme
213
219
$ this ->addMenuArea (['primary ' , 'user ' ]);
220
+
221
+
222
+ Hook::add ('TemplateManager::display ' , array ($ this , 'checkCurrentPage ' ));
214
223
}
215
224
216
225
/**
217
- * Get the name of the settings file to be installed on new press
226
+ * Get the name of the settings file to be installed on new journal
218
227
* creation.
219
228
*
220
229
* @return string
@@ -254,6 +263,57 @@ public function getDescription()
254
263
{
255
264
return __ ('plugins.themes.default.description ' );
256
265
}
266
+
267
+ /**
268
+ * @param $hookname string
269
+ * @param $args array
270
+ */
271
+ public function checkCurrentPage ($ hookname , $ args ) {
272
+ $ templateMgr = $ args [0 ];
273
+ // TODO check the issue with multiple calls of the hook on settings/website
274
+ if (!isset ($ templateMgr ->registered_plugins ["function " ]["default_item_active " ])) {
275
+ $ templateMgr ->registerPlugin ('function ' , 'default_item_active ' , array ($ this , 'isActiveItem ' ));
276
+ }
277
+
278
+ }
279
+
280
+ /**
281
+ * @param $params array
282
+ * @param $smarty Smarty_Internal_Template
283
+ * @return string
284
+ */
285
+ public function isActiveItem ($ params , $ smarty ) {
286
+
287
+ $ navigationMenuItem = $ params ['item ' ];
288
+ $ emptyMarker = '' ;
289
+ $ activeMarker = ' active ' ;
290
+
291
+ // Get URL of the current page
292
+ $ request = $ this ->getRequest ();
293
+ $ currentUrl = $ request ->getCompleteUrl ();
294
+ $ currentPage = $ request ->getRequestedPage ();
295
+
296
+ // Do not add an active marker if it's a dropdown menu
297
+ if ($ navigationMenuItem ->getIsChildVisible ()) return $ emptyMarker ;
298
+
299
+ // Retrieve URL and its components for a menu item
300
+ $ itemUrl = $ navigationMenuItem ->getUrl ();
301
+
302
+ // Check whether menu item points to the current page
303
+ /*$context = $request->getContext();
304
+ if ($context) {
305
+ $currentIssue = Repo::issue()->getCurrent($context->getId());
306
+ if ($navigationMenuItem->getType() === NavigationMenuService::NMI_TYPE_CURRENT) {
307
+ $issue = $smarty->getTemplateVars('issue');
308
+ if ($issue && ($issue->getId() === $currentIssue->getId()) && $currentPage == "issue") return $activeMarker;
309
+ }
310
+ }*/
311
+
312
+ if ($ currentUrl === $ itemUrl ) return $ activeMarker ;
313
+
314
+ return $ emptyMarker ;
315
+ }
316
+
257
317
}
258
318
259
319
if (!PKP_STRICT_MODE ) {
0 commit comments