-
Notifications
You must be signed in to change notification settings - Fork 0
/
BulmaThemePlugin.inc.php
executable file
·238 lines (196 loc) · 6.55 KB
/
BulmaThemePlugin.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/**
* @file plugins/themes/default/BulmaThemePlugin.php
*
* Copyright (c) 2024 Rafael Martínez Estévez
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class BulmaThemePlugin
* @ingroup plugins_themes_bulma
*
* @brief Default theme
*/
import('lib.pkp.classes.plugins.ThemePlugin');
class BulmaThemePlugin extends ThemePlugin
{
/**
* Initialize the theme's styles, scripts and hooks. This is only run for
* the currently active theme.
*
* @return null
*/
public function init()
{
$primaryColor = 'rgb(45, 44, 113)';
$linkColor = 'rgb(219, 143, 54)';
$this->addStyle(
'bulma',
'resources/main.css'
);
// Styles for HTML galleys
$this->addStyle('htmlGalley', 'templates/plugins/generic/htmlArticleGalley/css/default.css', array('contexts' => 'htmlGalley'));
$this->addStyle(
'glide',
'resources/glidejs/glide.core.min.css'
);
$this->addMenuArea(array('primary', 'user'));
$request = Application::get()->getRequest();
$min = Config::getVar('general', 'enable_minified') ? '.min' : '';
$jquery = $request->getBaseUrl() . '/lib/pkp/lib/vendor/components/jquery/jquery' . $min . '.js';
$jqueryUI = $request->getBaseUrl() . '/lib/pkp/lib/vendor/components/jqueryui/jquery-ui' . $min . '.js';
// Use an empty `baseUrl` argument to prevent the theme from looking for
// the files within the theme directory
// $this->addScript('jQueryUI', $jqueryUI, array('baseUrl' => ''));
$colors_vars = 'var primaryColor = "' . $primaryColor. '";';
$colors_vars .= 'var linkColor = "' . $linkColor. '";';
$this->addScript('themecolors', $colors_vars, array(
'inline' => true,
));
$this->addScript('initialfix', 'resources/js/initial.js');
$this->addScript('glidejs', 'resources/glidejs/glide.min.js');
$this->addScript('jQuery', $jquery, array('baseUrl' => ''));
$this->addScript(
'endfix',
'resources/js/end.js',
array(
'priority' => 1000,
)
);
// $this->addScript('collapsable', '/resources/js/collapsable.js');
// $this->addScript('search', '/resources/js/search.js');
// $this->addScript('collapsible', '/resources/collapsible/bulma-collapsible.min.js');
$this->addThemeOptions();
HookRegistry::register('TemplateManager::display', array($this, 'loadAdditionalData'));
// Check if CSS embedded to the HTML galley
HookRegistry::register('TemplateManager::display', array($this, 'hasEmbeddedCSS'));
}
public function loadAdditionalData($hookName, $args)
{
$smarty = $args[0];
$request = $this->getRequest();
$context = $request->getContext();
if (!defined('SESSION_DISABLE_INIT')) {
// Get possible locales
if ($context) {
$locales = $context->getSupportedLocaleNames();
} else {
$locales = $request->getSite()->getSupportedLocaleNames();
}
// $orcidImageUrl = $this->getPluginPath() . '/' . ORCID_IMAGE_URL;
$smarty->assign(array(
'languageToggleLocales' => $locales,
// 'orcidImageUrl' => $orcidImageUrl,
));
}
}
/**
* Get the display name of this plugin
* @return string
*/
function getDisplayName()
{
return __('plugins.themes.bulma.name');
}
/**
* Get the description of this plugin
* @return string
*/
function getDescription()
{
return __('plugins.themes.bulma.description');
}
/**
* @param $hookName string `TemplateManager::display`
* @param $args array [
* @option TemplateManager
* @option string relative path to the template
* ]
*/
public function hasEmbeddedCSS($hookName, $args)
{
$templateMgr = $args[0]; /* @var $templateMgr TemplateManager */
$template = $args[1];
$request = $this->getRequest();
// Return false if not a galley page
if ($template !== 'plugins/plugins/generic/htmlArticleGalley/generic/htmlArticleGalley:display.tpl') return false;
$articleArrays = $templateMgr->getTemplateVars('article');
// Deafult styling for HTML galley
$boolEmbeddedCss = false;
foreach ($articleArrays->getGalleys() as $galley) {
if ($galley->getFileType() === 'text/html') {
$submissionFile = $galley->getFile();
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
import('lib.pkp.classes.submission.SubmissionFile'); // Constants
$embeddableFiles = array_merge(
$submissionFileDao->getLatestRevisions($submissionFile->getSubmissionId(), SUBMISSION_FILE_PROOF),
$submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getFileId(), $submissionFile->getSubmissionId(), SUBMISSION_FILE_DEPENDENT)
);
foreach ($embeddableFiles as $embeddableFile) {
if ($embeddableFile->getFileType() == 'text/css') {
$boolEmbeddedCss = true;
}
}
}
}
$templateMgr->assign(array(
'boolEmbeddedCss' => $boolEmbeddedCss,
'themePath' => $request->getBaseUrl() . "/" . $this->getPluginPath(),
));
}
function addThemeOptions(){
$this->addOption('issnCode', 'FieldText', [
'label' => __('plugins.themes.bulma.issncode'),
'default' => null,
]);
$this->addOption('showTitleInJournalIndex', 'FieldOptions', [
'label' => __('plugins.themes.default.option.showTitleInJournalIndex.option'),
'options' => [
[
'value' => true,
'label' => __('plugins.themes.default.option.showTitleInJournalIndex.option'),
],
],
'default' => false,
]);
$this->addOption('showDescriptionInJournalIndex', 'FieldOptions', [
'label' => __('plugins.themes.default.option.showDescriptionInJournalIndex.option'),
'options' => [
[
'value' => true,
'label' => __('plugins.themes.default.option.showDescriptionInJournalIndex.option'),
],
],
'default' => false,
]);
$this->addOption('useHomepageImageAsHeader', 'FieldOptions', [
'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.option'),
'options' => [
[
'value' => true,
'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.option'),
],
],
'default' => false,
]);
$this->addOption('facebookLink', 'FieldText', [
'label' => __('plugins.themes.bulma.link.facebook'),
'default' => null,
]);
$this->addOption('twitterLink', 'FieldText', [
'label' => __('plugins.themes.bulma.link.twitter'),
'default' => null,
]);
$this->addOption('linkedinLink', 'FieldText', [
'label' => __('plugins.themes.bulma.link.linkedin'),
'default' => null,
]);
$this->addOption('instagramLink', 'FieldText', [
'label' => __('plugins.themes.bulma.link.instagram'),
'default' => null,
]);
$this->addOption('youtubeLink', 'FieldText', [
'label' => __('plugins.themes.bulma.link.youtube'),
'default' => null,
]);
}
}