forked from pkp/customBlockManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomBlockPlugin.inc.php
More file actions
136 lines (114 loc) · 3.28 KB
/
Copy pathCustomBlockPlugin.inc.php
File metadata and controls
136 lines (114 loc) · 3.28 KB
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
<?php
/**
* @file plugins/generic/customBlockManager/CustomBlockPlugin.inc.php
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 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 CustomBlockManagerPlugin Parent plugin */
var $_parentPlugin;
/**
* Constructor
* @param $blockName string Name of this block plugin.
* @param $parentPlugin CustomBlockManagerPlugin Custom block plugin management plugin.
*/
function __construct($blockName, $parentPlugin) {
$this->_blockName = $blockName;
$this->_parentPlugin = $parentPlugin;
parent::__construct();
}
/**
* Get the management plugin
* @return CustomBlockManagerPlugin
*/
function getManagerPlugin() {
return $this->_parentPlugin;
}
/**
* @copydoc Plugin::getName()
*/
function getName() {
return $this->_blockName;
}
/**
* @copydoc Plugin::getPluginPath()
*/
function getPluginPath() {
$plugin = $this->getManagerPlugin();
return $plugin->getPluginPath();
}
/**
* @copydoc Plugin::getTemplatePath()
*/
function getTemplatePath($inCore = false) {
$plugin = $this->getManagerPlugin();
return $plugin->getTemplatePath($inCore);
}
/**
* @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) {
$context = $request->getContext();
$contextId = $context ? $context->getId() : 0;
// Get the block contents.
$customBlockContent = $this->getSetting($contextId, 'blockContent');
$currentLocale = AppLocale::getLocale();
$contextPrimaryLocale = $context?$context->getPrimaryLocale():$request->getSite()->getPrimaryLocale();
$divCustomBlockId = 'customblock-'.preg_replace('/\W+/', '-', $this->getName());
$templateMgr->assign('customBlockId', $divCustomBlockId);
$content = $customBlockContent[$currentLocale] ? $customBlockContent[$currentLocale] : $customBlockContent[$contextPrimaryLocale];
$templateMgr->assign('customBlockContent', $content);
return parent::getContents($templateMgr, $request);
}
/**
* @copydoc BlockPlugin::getBlockContext()
*/
function getBlockContext() {
if (!Config::getVar('general', 'installed')) return BLOCK_CONTEXT_SIDEBAR;
return parent::getBlockContext();
}
/**
* @copydoc BlockPlugin::getSeq()
*/
function getSeq($contextId = null) {
if (!Config::getVar('general', 'installed')) return 1;
return parent::getSeq($contextId);
}
}
?>