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