-
Notifications
You must be signed in to change notification settings - Fork 1
/
LanguageToggleBlockPlugin.inc.php
102 lines (87 loc) · 2.7 KB
/
LanguageToggleBlockPlugin.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
<?php
/**
* @file plugins/blocks/languageToggle/LanguageToggleBlockPlugin.inc.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class LanguageToggleBlockPlugin
* @ingroup plugins_blocks_languageToggle
*
* @brief Class for language selector block plugin
*/
import('lib.pkp.classes.plugins.BlockPlugin');
class LanguageToggleBlockPlugin extends BlockPlugin {
/**
* Install default settings on system install.
* @return string
*/
function getInstallSitePluginSettingsFile() {
return $this->getPluginPath() . '/settings.xml';
}
/**
* Install default settings on journal creation.
* @return string
*/
function getContextSpecificPluginSettingsFile() {
return $this->getPluginPath() . '/settings.xml';
}
/**
* Get the display name of this plugin.
* @return String
*/
function getDisplayName() {
return __('plugins.block.languageToggle.displayName');
}
/**
* Get a description of the plugin.
*/
function getDescription() {
return __('plugins.block.languageToggle.description');
}
/**
* Get the HTML contents for this block.
* @param $templateMgr object
* @param $request PKPRequest
*/
function getContents($templateMgr, $request = null) {
if (!defined('SESSION_DISABLE_INIT')) {
// Check if the method getJournal() exists in $request object
if (method_exists($request, 'getJournal')) {
$journal = $request->getJournal();
if (isset($journal)) {
$locales = $journal->getSupportedLocaleNames();
} else {
$site = $request->getSite();
$locales = $site->getSupportedLocaleNames();
}
} else {
// Assuming we are in the context of OMP
$press = $request->getPress();
if (isset($press)) {
$locales = $press->getSupportedLocaleNames();
} else {
$site = $request->getSite();
$locales = $site->getSupportedLocaleNames();
}
if (isset($_SERVER['HTTP_REFERER'])) {
$templateMgr->assign('languageToggleNoUser', true);
$templateMgr->assign('referrerUrl', $_SERVER['HTTP_REFERER']);
} else {
unset($locales); // Disable; we're not sure what URL to use
}
}
} else {
// This part might need adjustment depending on how you handle locales in SESSION_DISABLE_INIT case
$locales = AppLocale::getAllLocales();
$templateMgr->assign('languageToggleNoUser', true);
}
if (isset($locales) && count($locales) > 1) {
$templateMgr->assign('enableLanguageToggle', true);
$templateMgr->assign('languageToggleLocales', $locales);
$templateMgr->assign('iconUrl', 'plugins/blocks/languageToggle/locale');
}
return parent::getContents($templateMgr, $request);
}
}