diff --git a/CustomBlockManagerPlugin.inc.php b/CustomBlockManagerPlugin.inc.php
index a57b115..a95f751 100644
--- a/CustomBlockManagerPlugin.inc.php
+++ b/CustomBlockManagerPlugin.inc.php
@@ -14,6 +14,12 @@
*
*/
+// No constant name in core 3.2 (!?!), per https://github.com/pkp/pkp-lib/commit/a76bac72ed068a1d1866398d20cdf28c4977249f#diff-70caff5ef9a513397af1833a3e2a3c7c
+import('lib.pkp.classes.plugins.BlockPlugin');
+if (!defined('BLOCK_CONTEXT_SIDEBAR')) {
+ define('BLOCK_CONTEXT_SIDEBAR', 1);
+}
+
import('lib.pkp.classes.plugins.GenericPlugin');
class CustomBlockManagerPlugin extends GenericPlugin {
@@ -62,7 +68,7 @@ function register($category, $path, $mainContextId = null) {
foreach ($blocks as $block) {
PluginRegistry::register(
'blocks',
- new CustomBlockPlugin($block, $this),
+ new CustomBlockPlugin($block, $this, $contextId),
$this->getPluginPath()
);
}
@@ -146,4 +152,76 @@ function manage($args, $request) {
function isSitePlugin() {
return !Application::getRequest()->getContext();
}
+
+ /**
+ * Create a unique name for a child plugin
+ *
+ * @return string
+ */
+ function createUniqueName() {
+ return str_replace('.', 'x', uniqid($this->getUniqueNamePrefix(), true));
+ }
+
+ /**
+ * Get the name prefix for a child plugin
+ *
+ * @return string
+ */
+ function getUniqueNamePrefix() {
+ return $this->getName().'__';
+ }
+
+ /**
+ * We will need to modify data in certain upgrades.
+ *
+ * @param $hookName string
+ * @param $args array
+ * @return boolean
+ */
+ function installFilters($hookName, $args) {
+ // There is no opportunity to hook the upgrade event before the new version is written to the versions table.
+ // The only function automatically called in installPluginVersion::execute() is installFilters(), so we hijack this.
+ // So, we need to look at the immediately preceeding version, and (re)apply fixes based on guesswork.
+ $versionDao = DAORegistry::getDAO('VersionDAO');
+ $contextDao = Application::getContextDAO();
+ $historicVersions = $versionDao->getVersionHistory('plugins.generic', 'customBlockManager');
+ if (count($historicVersions) > 1 && $historicVersions[1]->compare('1.3.0') < 0) {
+ // The last installed version is prior to 1.3.0
+ // We need up update the plugin_settings names and move any orphaned sidebar contexts
+ $contexts = $contextDao->getAll();
+ while ($context = $contexts->next()) {
+ // Load the custom blocks we have created
+ $blocks = $this->getSetting($context->getId(), 'blocks');
+ if (!is_array($blocks)) $blocks = array();
+ $pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO');
+ $newBlocks = array();
+ foreach ($blocks as $blockName) {
+ // Current block uses old naming
+ if (strpos($blockName, $this->getUniqueNamePrefix()) !== 0) {
+ $newBlockName = $this->createUniqueName();
+ // Update plugin_settings
+ $settings = $pluginSettingsDao->getPluginSettings($context->getId(), $blockName);
+ foreach ($settings as $setting_name => $setting_value) {
+ switch ($setting_name) {
+ case 'context':
+ $setting_value = BLOCK_CONTEXT_SIDEBAR;
+ case 'blockContent':
+ case 'enabled':
+ case 'seq':
+ $pluginSettingsDao->deleteSetting($context->getId(), $blockName, $setting_name);
+ $pluginSettingsDao->updateSetting($context->getId(), $newBlockName, $setting_name, $setting_value);
+ break;
+ default:
+ error_log('found an unrecognized setting "'.$setting_name.'", in custom block "'.$blockName.'"');
+ }
+ }
+ $pluginSettingsDao->updateSetting($context->getId(), $newBlockName, 'blockDisplayName', $blockName);
+ }
+ $newBlocks[] = $newBlockName;
+ }
+ $this->updateSetting($context->getId(), 'blocks', $newBlocks);
+ }
+ }
+ return parent::installFilters($hookName, $args);
+ }
}
diff --git a/CustomBlockPlugin.inc.php b/CustomBlockPlugin.inc.php
index a5b8b78..015d86e 100644
--- a/CustomBlockPlugin.inc.php
+++ b/CustomBlockPlugin.inc.php
@@ -19,6 +19,8 @@
class CustomBlockPlugin extends BlockPlugin {
/** @var string Name of this block plugin */
var $_blockName;
+ /** @var int Context ID */
+ var $_contextId;
/** @var CustomBlockManagerPlugin Parent plugin */
var $_parentPlugin;
@@ -27,10 +29,12 @@ class CustomBlockPlugin extends BlockPlugin {
* Constructor
* @param $blockName string Name of this block plugin.
* @param $parentPlugin CustomBlockManagerPlugin Custom block plugin management plugin.
+ * @param $contextId int The context in which this plugin lives
*/
- function __construct($blockName, $parentPlugin) {
+ function __construct($blockName, $parentPlugin, $contextId) {
$this->_blockName = $blockName;
$this->_parentPlugin = $parentPlugin;
+ $this->_contextId = $contextId;
parent::__construct();
}
@@ -84,7 +88,7 @@ function getEnabled($contextId = null) {
* @copydoc Plugin::getDisplayName()
*/
function getDisplayName() {
- return $this->_blockName . ' ' . __('plugins.generic.customBlock.nameSuffix');
+ return $this->getSetting($this->_contextId, 'blockDisplayName') . ' ' . __('plugins.generic.customBlock.nameSuffix');
}
/**
diff --git a/controllers/grid/CustomBlockGridHandler.inc.php b/controllers/grid/CustomBlockGridHandler.inc.php
index ae3f4fd..bc537f0 100644
--- a/controllers/grid/CustomBlockGridHandler.inc.php
+++ b/controllers/grid/CustomBlockGridHandler.inc.php
@@ -68,8 +68,9 @@ function initialize($request, $args = null) {
$blocks = $customBlockManagerPlugin->getSetting($contextId, 'blocks');
$gridData = array();
if (is_array($blocks)) foreach ($blocks as $block) {
+ $plugin = new CustomBlockPlugin($block, $customBlockManagerPlugin, $contextId);
$gridData[$block] = array(
- 'title' => $block
+ 'title' => $plugin->getSetting($contextId, 'blockDisplayName')
);
}
$this->setGridDataElements($gridData);
@@ -134,7 +135,7 @@ function addCustomBlock($args, $request) {
function editCustomBlock($args, $request) {
$blockName = $request->getUserVar('blockName');
$context = $request->getContext();
- $contextId = $context ? $context->getId() : 0;
+ $contextId = $context ? $context->getId() : CONTEXT_ID_NONE;
$this->setupTemplate($request);
$customBlockPlugin = null;
@@ -142,7 +143,7 @@ function editCustomBlock($args, $request) {
if ($blockName) {
// Create the custom block plugin
import('plugins.generic.customBlockManager.CustomBlockPlugin');
- $customBlockPlugin = new CustomBlockPlugin($blockName, CUSTOMBLOCKMANAGER_PLUGIN_NAME);
+ $customBlockPlugin = new CustomBlockPlugin($blockName, $this->plugin, $contextId);
}
// Create and present the edit form
@@ -171,7 +172,7 @@ function updateCustomBlock($args, $request) {
if ($pluginName) {
// Create the custom block plugin
import('plugins.generic.customBlockManager.CustomBlockPlugin');
- $customBlockPlugin = new CustomBlockPlugin($pluginName, CUSTOMBLOCKMANAGER_PLUGIN_NAME);
+ $customBlockPlugin = new CustomBlockPlugin($pluginName, $this->plugin, $contextId);
}
// Create and populate the form
diff --git a/controllers/grid/form/CustomBlockForm.inc.php b/controllers/grid/form/CustomBlockForm.inc.php
index 88640fd..f437709 100644
--- a/controllers/grid/form/CustomBlockForm.inc.php
+++ b/controllers/grid/form/CustomBlockForm.inc.php
@@ -38,8 +38,7 @@ function __construct($template, $contextId, $plugin = null) {
// Add form checks
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
- $this->addCheck(new FormValidator($this, 'blockName', 'required', 'plugins.generic.customBlock.nameRequired'));
- $this->addCheck(new FormValidatorRegExp($this, 'blockName', 'required', 'plugins.generic.customBlock.nameRegEx', '/^[a-zA-Z0-9_-]+$/'));
+ $this->addCheck(new FormValidator($this, 'blockDisplayName', 'required', 'plugins.generic.customBlock.nameRequired'));
}
/**
@@ -49,23 +48,23 @@ function initData() {
$contextId = $this->contextId;
$plugin = $this->plugin;
- $templateMgr = TemplateManager::getManager();
-
$blockName = null;
$blockContent = null;
if ($plugin) {
$blockName = $plugin->getName();
+ $blockDisplayName = $plugin->getSetting($contextId, 'blockDisplayName');
$blockContent = $plugin->getSetting($contextId, 'blockContent');
}
$this->setData('blockContent', $blockContent);
$this->setData('blockName', $blockName);
+ $this->setData('blockDisplayName', $blockDisplayName);
}
/**
* Assign form data to user-submitted data.
*/
function readInputData() {
- $this->readUserVars(array('blockName', 'blockContent'));
+ $this->readUserVars(array('blockName', 'blockDisplayName', 'blockContent'));
}
/**
@@ -74,11 +73,13 @@ function readInputData() {
function execute() {
$plugin = $this->plugin;
$contextId = $this->contextId;
+ $blockName = $this->getData('blockName');
if (!$plugin) {
// Create a new custom block plugin
import('plugins.generic.customBlockManager.CustomBlockPlugin');
$customBlockManagerPlugin = PluginRegistry::getPlugin('generic', CUSTOMBLOCKMANAGER_PLUGIN_NAME);
- $plugin = new CustomBlockPlugin($this->getData('blockName'), $customBlockManagerPlugin);
+ $blockName = $customBlockManagerPlugin->createUniqueName();
+ $plugin = new CustomBlockPlugin($blockName, $customBlockManagerPlugin, $contextId);
// Default the block to being enabled
$plugin->setEnabled(true);
@@ -90,12 +91,13 @@ function execute() {
$blocks = $customBlockManagerPlugin->getSetting($contextId, 'blocks');
if (!isset($blocks)) $blocks = array();
- array_push($blocks, $this->getData('blockName'));
+ $blocks[] = $blockName;
$customBlockManagerPlugin->updateSetting($contextId, 'blocks', $blocks);
}
// update custom block plugin content
$plugin->updateSetting($contextId, 'blockContent', $this->getData('blockContent'));
+ $plugin->updateSetting($contextId, 'blockDisplayName', $this->getData('blockDisplayName'));
}
}
diff --git a/locale/ar_IQ/locale.xml b/locale/ar_IQ/locale.xml
index aa86fc3..aafa4f7 100644
--- a/locale/ar_IQ/locale.xml
+++ b/locale/ar_IQ/locale.xml
@@ -24,5 +24,4 @@
(إضافة الكتلة المخصصة)
هذه كتلة مولدة من قبل المستخدم.
اسم الكتلة المخصصة مطلوب حتماً.
- اسم الكتلة المخصصة يجب أن يقتصر على الحروف والأرقام وعلامة الطرح والخط التحتاني.
diff --git a/locale/cs_CZ/locale.xml b/locale/cs_CZ/locale.xml
index d632b5c..16c8164 100644
--- a/locale/cs_CZ/locale.xml
+++ b/locale/cs_CZ/locale.xml
@@ -24,5 +24,4 @@
(Plugin uživatelských panelů)
Tento plugin vám umožňuje spravovat (přidávat, upravovat a odstraňovat) vlastní bloky v postranních panelech.
Je třeba zadat jméno uživatelského bloku.
- Název uživatelského bloku musí obsahovat pouze písmena, čísla a pomlčky/podtržítka.
diff --git a/locale/da_DK/locale.xml b/locale/da_DK/locale.xml
index 04c0aaa..6e09869 100644
--- a/locale/da_DK/locale.xml
+++ b/locale/da_DK/locale.xml
@@ -24,5 +24,4 @@
(Brugerdefineret blok)
Dette er et brugerdefineret element.
Et brugerdefineret blok-navn er påkrævet.
- Det brugerdefinerede blok-navn må indeholde bogstaver, numre og bindestreg/understregning.
diff --git a/locale/de_DE/locale.xml b/locale/de_DE/locale.xml
index 29d1760..deafc8c 100644
--- a/locale/de_DE/locale.xml
+++ b/locale/de_DE/locale.xml
@@ -24,5 +24,4 @@
(Benutzerdefinierter Block)
Dies ist ein selbst angelegter Block.
Der Name des benutzerdefinierten Blocks wird benötigt.
- Der Name des benutzerdefinierten Blocks darf nur Buchstaben, Ziffern und Bindestriche/Unterstriche enthalten.
diff --git a/locale/en_US/locale.xml b/locale/en_US/locale.xml
index 65d8a4e..f1639b7 100644
--- a/locale/en_US/locale.xml
+++ b/locale/en_US/locale.xml
@@ -24,5 +24,4 @@
(Custom Block)
This is a user-generated block.
The custom block name is required.
- The custom block name must contain only letters, numbers, and hyphens/underscores.
diff --git a/locale/es_ES/locale.xml b/locale/es_ES/locale.xml
index 24d26b1..6ee87bd 100644
--- a/locale/es_ES/locale.xml
+++ b/locale/es_ES/locale.xml
@@ -24,5 +24,4 @@
(Bloque Personalizado)
Este es un Bloque generado por el usuario.
Se requiere el nombre del bloque personalizado.
- El nombre del bloque personalizado sólo debe contener letras, números y guiones/guiones bajos.
diff --git a/locale/fi_FI/locale.xml b/locale/fi_FI/locale.xml
index a26ed42..a078c4c 100644
--- a/locale/fi_FI/locale.xml
+++ b/locale/fi_FI/locale.xml
@@ -24,5 +24,4 @@
(Mukautettu lohko)
Tämä on käyttäjän luoma lohko.
Mukautetun lohkon nimi vaaditaan.
- Mukautetun lohkon nimi voi sisältää vain kirjaimia, numeroita ja yhdysmerkkejä/alaviivoja.
diff --git a/locale/fr_CA/locale.xml b/locale/fr_CA/locale.xml
index 22139bb..aa0ad66 100644
--- a/locale/fr_CA/locale.xml
+++ b/locale/fr_CA/locale.xml
@@ -25,5 +25,4 @@
Blocs personnalisés
Aucun bloc personnalisé n'a été créé.
Le nom du bloc personnalisé est requis.
- Le nom du bloc personnalisé ne doit contenir que des lettres, des chiffres, des tirets et/ou des traits de soulignement.
diff --git a/locale/it_IT/locale.xml b/locale/it_IT/locale.xml
index a3b3612..a46d453 100644
--- a/locale/it_IT/locale.xml
+++ b/locale/it_IT/locale.xml
@@ -24,5 +24,4 @@
(blocco personalizzato)
Questo è un blocco generato dall'utente.
Il nome del blocco personalizzato è necessario
- Il nome del blocco personalizzato può contenere solo lettere, numeri e trattini alti o bassi.
diff --git a/locale/nl_NL/locale.xml b/locale/nl_NL/locale.xml
index 81012bb..e6ffdb3 100644
--- a/locale/nl_NL/locale.xml
+++ b/locale/nl_NL/locale.xml
@@ -25,5 +25,4 @@
(Eigen blokken plugin)
Dit is een zelfgemaakt blok.
Een naam is verplicht voor het eigen blok.
- De naam van het eigen blok mag uitsluitend letters, cijfers en koppeltekens of liggende streepjes bevatten.
diff --git a/locale/pt_BR/locale.xml b/locale/pt_BR/locale.xml
index 1368b86..527fbcd 100644
--- a/locale/pt_BR/locale.xml
+++ b/locale/pt_BR/locale.xml
@@ -25,5 +25,4 @@
Blocos Personalizados
Não há blocos personalizados criados.
O nome do bloco personalizado é necessário.
- O nome do bloco personalizado deve conter apenas letras, números e hífens / sublinhados.
diff --git a/locale/pt_PT/locale.xml b/locale/pt_PT/locale.xml
index ed59136..ea56f39 100644
--- a/locale/pt_PT/locale.xml
+++ b/locale/pt_PT/locale.xml
@@ -25,5 +25,4 @@
Blocos Personalizados
Nenhum bloco personalizado criado.
O nome do bloco personalizado é obrigatório.
- O nome do bloco personalizado só pode conter letras, números e hífenes ou sublinhados.
diff --git a/locale/ru_RU/locale.xml b/locale/ru_RU/locale.xml
index 4d95810..fe66f61 100644
--- a/locale/ru_RU/locale.xml
+++ b/locale/ru_RU/locale.xml
@@ -24,5 +24,4 @@
(пользовательский блок)
Это пользовательский блок.
Имя пользовательского блока обязательно.
- Имя пользовательского блока должно содержать только буквы, цифры, дефисы и подчеркивания.
diff --git a/locale/sl_SI/locale.xml b/locale/sl_SI/locale.xml
index 54dcc1a..65d8ad3 100644
--- a/locale/sl_SI/locale.xml
+++ b/locale/sl_SI/locale.xml
@@ -24,5 +24,4 @@
(Uporabniški blok)
To blok, ki ga je ustvaril uporabnik.
Ime bloka je obvezno.
- Ime bloka lahko vsebuje le črke, številke in pomišljaj/podčrtaj.
diff --git a/locale/sr_RS@latin/locale.xml b/locale/sr_RS@latin/locale.xml
index 2c53ff9..0b314c2 100644
--- a/locale/sr_RS@latin/locale.xml
+++ b/locale/sr_RS@latin/locale.xml
@@ -23,5 +23,4 @@
Prilagođeni blokovi
Nema prilagođenih blokova.
Ime bloka je oavezno.
- Ime bloka može sadržati samo slova, brojeve, crte i podvlake.
diff --git a/locale/sv_SE/locale.xml b/locale/sv_SE/locale.xml
index 9ac4f7d..ca1a543 100644
--- a/locale/sv_SE/locale.xml
+++ b/locale/sv_SE/locale.xml
@@ -24,5 +24,4 @@
(Anpassat block)
Det här är ett användargenererat block.
Ett namn på det anpassade blocket krävs.
- Det anpassade blockets namn får bara innehålla bokstäver, siffror och bindestreck/understreck.
diff --git a/locale/tr_TR/locale.xml b/locale/tr_TR/locale.xml
index b3218e2..de293e8 100644
--- a/locale/tr_TR/locale.xml
+++ b/locale/tr_TR/locale.xml
@@ -25,5 +25,4 @@
Özel Bloklar
Özel blok oluşturulmadı.
Özel blok adı gerekli.
- Özel blok adı sadece harf, sayı ve kısa çizgi / alt çizgi içermelidir.
diff --git a/locale/uk_UA/locale.xml b/locale/uk_UA/locale.xml
index 1b07838..efd3085 100644
--- a/locale/uk_UA/locale.xml
+++ b/locale/uk_UA/locale.xml
@@ -24,5 +24,4 @@
(власний блок)
Це створений користувачем блок.
Назва власного блоку обов'язкова.
- Назва власного блоку повинна містити лише літери, цифри, дефіс та підкреслювання.
diff --git a/templates/editCustomBlockForm.tpl b/templates/editCustomBlockForm.tpl
index 80a3a37..4e8252d 100644
--- a/templates/editCustomBlockForm.tpl
+++ b/templates/editCustomBlockForm.tpl
@@ -19,7 +19,8 @@
{csrf}
{fbvFormArea id="customBlocksFormArea" class="border"}
{fbvFormSection}
- {fbvElement type="text" label="plugins.generic.customBlockManager.blockName" id="blockName" value=$blockName maxlength="40" inline=true size=$fbvStyles.size.MEDIUM}
+ {fbvElement type="hidden" id="blockName" value=$blockName}
+ {fbvElement type="text" label="plugins.generic.customBlockManager.blockName" id="blockDisplayName" value=$blockDisplayName maxlength="40" inline=true size=$fbvStyles.size.MEDIUM}
{/fbvFormSection}
{fbvFormSection label="plugins.generic.customBlock.content" for="blockContent"}
{fbvElement type="textarea" multilingual=true name="blockContent" id="blockContent" value=$blockContent rich=true height=$fbvStyles.height.TALL}
diff --git a/version.xml b/version.xml
index 3e010d3..fe6698e 100644
--- a/version.xml
+++ b/version.xml
@@ -13,8 +13,8 @@
customBlockManager
plugins.generic
- 1.2.0.0
- 2014-09-19
+ 1.3.0.0
+ 2020-03-02
1
CustomBlockManagerPlugin