-
Notifications
You must be signed in to change notification settings - Fork 35
/
CustomBlockPlugin.php
149 lines (129 loc) · 4.03 KB
/
CustomBlockPlugin.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
<?php
/**
* @file plugins/generic/customBlockManager/CustomBlockPlugin.php
*
* Copyright (c) 2014-2020 Simon Fraser University
* Copyright (c) 2003-2020 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @package plugins.generic.customBlockManager
*
* @class CustomBlockPlugin
*
* A generic sidebar block that can be customized through the CustomBlockManagerPlugin
*
*/
namespace APP\plugins\generic\customBlockManager;
use APP\core\Application;
use PKP\facades\Locale;
use PKP\plugins\BlockPlugin;
class CustomBlockPlugin extends BlockPlugin
{
/** @var string Name of this block plugin */
public $_blockName;
/** @var CustomBlockManagerPlugin Parent plugin */
public $_parentPlugin;
/**
* Constructor
*
* @param string $blockName Name of this block plugin.
* @param CustomBlockManagerPlugin $parentPlugin Custom block plugin management plugin.
*/
public function __construct($blockName, $parentPlugin)
{
$this->_blockName = $blockName;
$this->_parentPlugin = $parentPlugin;
parent::__construct();
}
/**
* Get the management plugin
*
* @return CustomBlockManagerPlugin
*/
public function getManagerPlugin()
{
return $this->_parentPlugin;
}
/**
* @copydoc Plugin::getName()
*/
public function getName()
{
return $this->_blockName;
}
/**
* @copydoc Plugin::getPluginPath()
*/
public function getPluginPath()
{
$plugin = $this->getManagerPlugin();
return $plugin->getPluginPath();
}
/**
* @copydoc Plugin::getTemplatePath()
*/
public function getTemplatePath($inCore = false)
{
$plugin = $this->getManagerPlugin();
return $plugin->getTemplatePath($inCore);
}
/**
* @copydoc Plugin::getHideManagement()
*/
public function getHideManagement()
{
return true;
}
/**
* @copydoc LazyLoadPlugin::getEnabled()
*
* @param null|mixed $contextId
*/
public function getEnabled($contextId = null)
{
if (!Application::isInstalled()) {
return true;
}
return parent::getEnabled($contextId);
}
/**
* @copydoc Plugin::getDisplayName()
*/
public function getDisplayName()
{
return $this->_blockName . ' ' . __('plugins.generic.customBlock.nameSuffix');
}
/**
* @copydoc Plugin::getDescription()
*/
public function getDescription()
{
return __('plugins.generic.customBlock.description');
}
/**
* @copydoc BlockPlugin::getContents()
*
* @param null|mixed $request
*/
public function getContents($templateMgr, $request = null)
{
$context = $request->getContext();
$contextId = $context ? $context->getId() : Application::SITE_CONTEXT_ID;
// Get the block contents.
$customBlockTitle = $this->getSetting($contextId, 'blockTitle');
$customBlockContent = $this->getSetting($contextId, 'blockContent');
$currentLocale = Locale::getLocale();
$contextPrimaryLocale = $context ? $context->getPrimaryLocale() : $request->getSite()->getPrimaryLocale();
$divCustomBlockId = 'customblock-' . preg_replace('/\W+/', '-', $this->getName());
$templateMgr->assign('customBlockId', $divCustomBlockId);
$title = $customBlockTitle[$currentLocale] ? $customBlockTitle[$currentLocale] : $customBlockTitle[$contextPrimaryLocale];
$content = $customBlockContent[$currentLocale] ? $customBlockContent[$currentLocale] : $customBlockContent[$contextPrimaryLocale];
$templateMgr->assign('customBlockTitle', $title);
$templateMgr->assign('customBlockContent', $content);
$templateMgr->assign('showName', $this->getSetting($contextId, 'showName'));
return parent::getContents($templateMgr, $request);
}
}
if (!PKP_STRICT_MODE) {
class_alias('\APP\plugins\generic\customBlockManager\CustomBlockPlugin', '\CustomBlockPlugin');
}