Open Journal Systems  3.3.0
DefaultThemePlugin.inc.php
1 <?php
2 
16 import('lib.pkp.classes.plugins.ThemePlugin');
17 
22  public function isActive() {
23  if (defined('SESSION_DISABLE_INIT')) return true;
24  return parent::isActive();
25  }
26 
33  public function init() {
34  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_MANAGER, LOCALE_COMPONENT_APP_MANAGER);
35 
36  // Register theme options
37  $this->addOption('typography', 'FieldOptions', [
38  'type' => 'radio',
39  'label' => __('plugins.themes.default.option.typography.label'),
40  'description' => __('plugins.themes.default.option.typography.description'),
41  'options' => [
42  [
43  'value' => 'notoSans',
44  'label' => __('plugins.themes.default.option.typography.notoSans'),
45  ],
46  [
47  'value' => 'notoSerif',
48  'label' => __('plugins.themes.default.option.typography.notoSerif'),
49  ],
50  [
51  'value' => 'notoSerif_notoSans',
52  'label' => __('plugins.themes.default.option.typography.notoSerif_notoSans'),
53  ],
54  [
55  'value' => 'notoSans_notoSerif',
56  'label' => __('plugins.themes.default.option.typography.notoSans_notoSerif'),
57  ],
58  [
59  'value' => 'lato',
60  'label' => __('plugins.themes.default.option.typography.lato'),
61  ],
62  [
63  'value' => 'lora',
64  'label' => __('plugins.themes.default.option.typography.lora'),
65  ],
66  [
67  'value' => 'lora_openSans',
68  'label' => __('plugins.themes.default.option.typography.lora_openSans'),
69  ],
70  ],
71  'default' => 'notoSans',
72  ]);
73 
74  $this->addOption('baseColour', 'FieldColor', [
75  'label' => __('plugins.themes.default.option.colour.label'),
76  'description' => __('plugins.themes.default.option.colour.description'),
77  'default' => '#1E6292',
78  ]);
79 
80  $this->addOption('showDescriptionInJournalIndex', 'FieldOptions', [
81  'label' => __('manager.setup.contextSummary'),
82  'options' => [
83  [
84  'value' => true,
85  'label' => __('plugins.themes.default.option.showDescriptionInJournalIndex.option'),
86  ],
87  ],
88  'default' => false,
89  ]);
90  $this->addOption('useHomepageImageAsHeader', 'FieldOptions', [
91  'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.label'),
92  'description' => __('plugins.themes.default.option.useHomepageImageAsHeader.description'),
93  'options' => [
94  [
95  'value' => true,
96  'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.option')
97  ],
98  ],
99  'default' => false,
100  ]);
101 
102  // Load primary stylesheet
103  $this->addStyle('stylesheet', 'styles/index.less');
104 
105  // Store additional LESS variables to process based on options
106  $additionalLessVariables = array();
107 
108  // Load fonts from Google Font CDN
109  // To load extended latin or other character sets, see:
110  // https://www.google.com/fonts#UsePlace:use/Collection:Noto+Sans
111  if (Config::getVar('general', 'enable_cdn')) {
112 
113  if ($this->getOption('typography') === 'notoSerif') {
114  $this->addStyle(
115  'fontNotoSerif',
116  '//fonts.googleapis.com/css?family=Noto+Serif:400,400i,700,700i',
117  array('baseUrl' => '')
118  );
119  $additionalLessVariables[] = '@font: "Noto Serif", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif;';
120 
121  } elseif (strpos($this->getOption('typography'), 'notoSerif') !== false) {
122  $this->addStyle(
123  'fontNotoSansNotoSerif',
124  '//fonts.googleapis.com/css?family=Noto+Sans:400,400i,700,700i|Noto+Serif:400,400i,700,700i',
125  array('baseUrl' => '')
126  );
127 
128  // Update LESS font variables
129  if ($this->getOption('typography') == 'notoSerif_notoSans') {
130  $additionalLessVariables[] = '@font-heading: "Noto Serif", serif;';
131  } elseif ($this->getOption('typography') == 'notoSans_notoSerif') {
132  $additionalLessVariables[] = '@font: "Noto Serif", serif;@font-heading: "Noto Sans", serif;';
133  }
134 
135  } elseif ($this->getOption('typography') == 'lato') {
136  $this->addStyle(
137  'fontLato',
138  '//fonts.googleapis.com/css?family=Lato:400,400i,900,900i',
139  array('baseUrl' => '')
140  );
141  $additionalLessVariables[] = '@font: Lato, sans-serif;';
142 
143  } elseif ($this->getOption('typography') == 'lora') {
144  $this->addStyle(
145  'fontLora',
146  '//fonts.googleapis.com/css?family=Lora:400,400i,700,700i',
147  array('baseUrl' => '')
148  );
149  $additionalLessVariables[] = '@font: Lora, serif;';
150 
151  } elseif ($this->getOption('typography') == 'lora_openSans') {
152  $this->addStyle(
153  'fontLoraOpenSans',
154  '//fonts.googleapis.com/css?family=Lora:400,400i,700,700i|Open+Sans:400,400i,700,700i',
155  array('baseUrl' => '')
156  );
157  $additionalLessVariables[] = '@font: "Open Sans", sans-serif;@font-heading: Lora, serif;';
158 
159  } else {
160  $this->addStyle(
161  'fontNotoSans',
162  '//fonts.googleapis.com/css?family=Noto+Sans:400,400italic,700,700italic',
163  array('baseUrl' => '')
164  );
165  }
166  }
167 
168  // Update colour based on theme option
169  if ($this->getOption('baseColour') !== '#1E6292') {
170  $additionalLessVariables[] = '@bg-base:' . $this->getOption('baseColour') . ';';
171  if (!$this->isColourDark($this->getOption('baseColour'))) {
172  $additionalLessVariables[] = '@text-bg-base:rgba(0,0,0,0.84);';
173  $additionalLessVariables[] = '@bg-base-border-color:rgba(0,0,0,0.2);';
174  }
175  }
176 
177  // Pass additional LESS variables based on options
178  if (!empty($additionalLessVariables)) {
179  $this->modifyStyle('stylesheet', array('addLessVariables' => join($additionalLessVariables)));
180  }
181 
182  $request = Application::get()->getRequest();
183 
184  // Load icon font FontAwesome - http://fontawesome.io/
185  if (Config::getVar('general', 'enable_cdn')) {
186  $url = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css';
187  } else {
188  $url = $request->getBaseUrl() . '/lib/pkp/styles/fontawesome/fontawesome.css';
189  }
190  $this->addStyle(
191  'fontAwesome',
192  $url,
193  array('baseUrl' => '')
194  );
195 
196  // Get homepage image and use as header background if useAsHeader is true
197  $context = Application::get()->getRequest()->getContext();
198  if ($context && $this->getOption('useHomepageImageAsHeader')) {
199 
200  $publicFileManager = new PublicFileManager();
201  $publicFilesDir = $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($context->getId());
202 
203  $homepageImage = $context->getLocalizedData('homepageImage');
204 
205  $homepageImageUrl = $publicFilesDir . '/' . $homepageImage['uploadName'];
206 
207  $this->addStyle(
208  'homepageImage',
209  '.pkp_structure_head { background: center / cover no-repeat url("' . $homepageImageUrl . '");}',
210  ['inline' => true]
211  );
212  }
213 
214  // Load jQuery from a CDN or, if CDNs are disabled, from a local copy.
215  $min = Config::getVar('general', 'enable_minified') ? '.min' : '';
216  if (Config::getVar('general', 'enable_cdn')) {
217  $jquery = '//ajax.googleapis.com/ajax/libs/jquery/' . CDN_JQUERY_VERSION . '/jquery' . $min . '.js';
218  $jqueryUI = '//ajax.googleapis.com/ajax/libs/jqueryui/' . CDN_JQUERY_UI_VERSION . '/jquery-ui' . $min . '.js';
219  } else {
220  // Use OJS's built-in jQuery files
221  $jquery = $request->getBaseUrl() . '/lib/pkp/lib/vendor/components/jquery/jquery' . $min . '.js';
222  $jqueryUI = $request->getBaseUrl() . '/lib/pkp/lib/vendor/components/jqueryui/jquery-ui' . $min . '.js';
223  }
224  // Use an empty `baseUrl` argument to prevent the theme from looking for
225  // the files within the theme directory
226  $this->addScript('jQuery', $jquery, array('baseUrl' => ''));
227  $this->addScript('jQueryUI', $jqueryUI, array('baseUrl' => ''));
228  $this->addScript('jQueryTagIt', $request->getBaseUrl() . '/lib/pkp/js/lib/jquery/plugins/jquery.tag-it.js', array('baseUrl' => ''));
229 
230  // Load Bootsrap's dropdown
231  $this->addScript('popper', 'js/lib/popper/popper.js');
232  $this->addScript('bsUtil', 'js/lib/bootstrap/util.js');
233  $this->addScript('bsDropdown', 'js/lib/bootstrap/dropdown.js');
234 
235  // Load custom JavaScript for this theme
236  $this->addScript('default', 'js/main.js');
237 
238  // Add navigation menu areas for this theme
239  $this->addMenuArea(array('primary', 'user'));
240  }
241 
248  return $this->getPluginPath() . '/settings.xml';
249  }
250 
257  return $this->getPluginPath() . '/settings.xml';
258  }
259 
264  function getDisplayName() {
265  return __('plugins.themes.default.name');
266  }
267 
272  function getDescription() {
273  return __('plugins.themes.default.description');
274  }
275 }
ThemePlugin
Abstract class for theme plugins.
Definition: ThemePlugin.inc.php:21
ThemePlugin\isColourDark
isColourDark($color, $limit=130)
Definition: ThemePlugin.inc.php:845
DefaultThemePlugin\getInstallSitePluginSettingsFile
getInstallSitePluginSettingsFile()
Definition: DefaultThemePlugin.inc.php:256
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
ThemePlugin\addMenuArea
addMenuArea($menuAreas)
Definition: ThemePlugin.inc.php:662
DefaultThemePlugin\getDisplayName
getDisplayName()
Definition: DefaultThemePlugin.inc.php:264
ThemePlugin\getOption
getOption($name)
Definition: ThemePlugin.inc.php:454
ThemePlugin\addScript
addScript($name, $script, $args=array())
Definition: ThemePlugin.inc.php:304
ThemePlugin\addOption
addOption($name, $type, $args=array())
Definition: ThemePlugin.inc.php:393
PublicFileManager
Wrapper class for uploading files to a site/journal's public directory.
Definition: PublicFileManager.inc.php:18
DefaultThemePlugin\init
init()
Definition: DefaultThemePlugin.inc.php:33
Config\getVar
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
DefaultThemePlugin\getContextSpecificPluginSettingsFile
getContextSpecificPluginSettingsFile()
Definition: DefaultThemePlugin.inc.php:247
DefaultThemePlugin\isActive
isActive()
Definition: DefaultThemePlugin.inc.php:22
Plugin\getPluginPath
getPluginPath()
Definition: Plugin.inc.php:330
ThemePlugin\modifyStyle
modifyStyle($name, $args=array())
Definition: ThemePlugin.inc.php:229
Plugin\$request
$request
Definition: Plugin.inc.php:68
DefaultThemePlugin\getDescription
getDescription()
Definition: DefaultThemePlugin.inc.php:272
ThemePlugin\addStyle
addStyle($name, $style, $args=array())
Definition: ThemePlugin.inc.php:191
DefaultThemePlugin
Default theme.
Definition: DefaultThemePlugin.inc.php:18
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235