forked from pkp/customBlockManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomBlockPlugin.inc.php
132 lines (113 loc) · 3.11 KB
/
CustomBlockPlugin.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
<?php
/**
* @file plugins/generic/customBlockManager/CustomBlockPlugin.inc.php
*
* Copyright (c) 2014 Simon Fraser University Library
* Copyright (c) 2003-2014 John Willinsky
* Distributed under the GNU GPL v2. 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
*
*/
import('lib.pkp.classes.plugins.BlockPlugin');
class CustomBlockPlugin extends BlockPlugin {
/** @var string Name of this block plugin */
var $blockName;
/** @var string Name of parent plugin */
var $parentPluginName;
/**
* Constructor
* @param $blockName string Name of this block plugin.
* @param $parentPluginName string Name of block plugin management plugin.
*/
function CustomBlockPlugin($blockName, $parentPluginName) {
$this->blockName = $blockName;
$this->parentPluginName = $parentPluginName;
parent::BlockPlugin();
}
/**
* Get the management plugin
* @return CustomBlockManagerPlugin
*/
function &getManagerPlugin() {
return PluginRegistry::getPlugin('generic', $this->parentPluginName);
}
/**
* @copydoc Plugin::getName()
*/
function getName() {
return $this->blockName;
}
/**
* @copydoc Plugin::getPluginPath()
*/
function getPluginPath() {
$plugin =& $this->getManagerPlugin();
return $plugin->getPluginPath();
}
/**
* @copydoc Plugin::getTemplatePath()
*/
function getTemplatePath() {
$plugin =& $this->getManagerPlugin();
return $plugin->getTemplatePath();
}
/**
* @copydoc Plugin::getHideManagement()
*/
function getHideManagement() {
return true;
}
/**
* @copydoc LazyLoadPlugin::getEnabled()
*/
function getEnabled() {
if (!Config::getVar('general', 'installed')) return true;
return parent::getEnabled();
}
/**
* @copydoc Plugin::getDisplayName()
*/
function getDisplayName() {
return $this->blockName . ' ' . __('plugins.generic.customBlock.nameSuffix');
}
/**
* @copydoc Plugin::getDescription()
*/
function getDescription() {
return __('plugins.generic.customBlock.description');
}
/**
* @copydoc BlockPlugin::getContents()
*/
function getContents(&$templateMgr, $request = null) {
// Ensure that we're dealing with a request with context
$context = $request->getContext();
if (!$context) return '';
// Get the block contents.
$customBlockContent = $this->getSetting($context->getId(), 'blockContent');
$currentLocale = AppLocale::getLocale();
$divCustomBlockId = 'customblock-'.preg_replace('/\W+/', '-', $this->getName());
$templateMgr->assign('customBlockId', $divCustomBlockId);
$templateMgr->assign('customBlockContent', $customBlockContent[$currentLocale]);
return parent::getContents($templateMgr, $request);
}
/**
* @copydoc BlockPlugin::getBlockContext()
*/
function getBlockContext() {
if (!Config::getVar('general', 'installed')) return BLOCK_CONTEXT_RIGHT_SIDEBAR;
return parent::getBlockContext();
}
/**
* @copydoc BlockPlugin::getSeq()
*/
function getSeq() {
if (!Config::getVar('general', 'installed')) return 1;
return parent::getSeq();
}
}
?>