/** * Register as a block plugin, even though this is a generic plugin. * This will allow the plugin to behave as a block plugin, i.e. to * have layout tasks performed on it. * @param $hookName string * @param $args array */ function callbackLoadCategory($hookName, $args) { $category =& $args[0]; $plugins =& $args[1]; switch ($category) { case 'blocks': $this->import('CustomBlockPlugin'); $journal =& Request::getJournal(); if (!$journal) { return false; } $blocks = $this->getSetting($journal->getId(), 'blocks'); if (!is_array($blocks)) { break; } $i = 0; foreach ($blocks as $block) { $blockPlugin = new CustomBlockPlugin($block, $this->getName()); // default the block to being enabled if ($blockPlugin->getEnabled() !== false) { $blockPlugin->setEnabled(true); } // default the block to the right sidebar if (!is_numeric($blockPlugin->getBlockContext())) { $blockPlugin->setBlockContext(BLOCK_CONTEXT_RIGHT_SIDEBAR); } $plugins[$blockPlugin->getSeq()][$blockPlugin->getPluginPath() . $i] =& $blockPlugin; $i++; unset($blockPlugin); } break; } return false; }
/** * Save form values into the database */ function execute() { $plugin = $this->plugin; $contextId = $this->contextId; if (!$plugin) { // Create a new custom block plugin import('plugins.generic.customBlockManager.CustomBlockPlugin'); $plugin = new CustomBlockPlugin($this->getData('blockName'), CUSTOMBLOCKMANAGER_PLUGIN_NAME); // Default the block to being enabled $plugin->setEnabled(true); // Default the block to the left sidebar $plugin->setBlockContext(BLOCK_CONTEXT_SIDEBAR); // Add the custom block to the list of the custom block plugins in the // custom block manager plugin $customBlockManagerPlugin = $plugin->getManagerPlugin(); $blocks = $customBlockManagerPlugin->getSetting($contextId, 'blocks'); if (!isset($blocks)) { $blocks = array(); } array_push($blocks, $this->getData('blockName')); $customBlockManagerPlugin->updateSetting($contextId, 'blocks', $blocks); } // update custom block plugin content $plugin->updateSetting($contextId, 'blockContent', $this->getData('blockContent')); }
/** * Perform management functions */ function manage($verb, $args, &$message, &$messageParams) { if (!parent::manage($verb, $args, $message, $messageParams)) { return false; } switch ($verb) { case 'settings': $this->import('CustomBlockPlugin'); $journal =& Request::getJournal(); $templateMgr =& TemplateManager::getManager(); $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl')); $pageCrumbs = array(array(Request::url(null, 'user'), 'navigation.user'), array(Request::url(null, 'manager'), 'user.role.manager'), array(Request::url(null, 'manager', 'plugins'), __('manager.plugins'), true)); $templateMgr->assign('pageHierarchy', $pageCrumbs); $this->import('SettingsForm'); $form = new SettingsForm($this, $journal->getId()); $form->readInputData(); if (Request::getUserVar('addBlock')) { // Add a block $editData = true; $blocks = $form->getData('blocks'); array_push($blocks, ''); $form->_data['blocks'] = $blocks; } else { if (($delBlock = Request::getUserVar('delBlock')) && count($delBlock) == 1) { // Delete an block $editData = true; list($delBlock) = array_keys($delBlock); $delBlock = (int) $delBlock; $blocks = $form->getData('blocks'); if (isset($blocks[$delBlock]) && !empty($blocks[$delBlock])) { $deletedBlocks = explode(':', $form->getData('deletedBlocks')); array_push($deletedBlocks, $blocks[$delBlock]); $form->setData('deletedBlocks', join(':', $deletedBlocks)); } array_splice($blocks, $delBlock, 1); $form->_data['blocks'] = $blocks; } else { if (Request::getUserVar('save')) { $editData = true; $form->execute(); // Enable the block plugin and place it in the right sidebar if ($form->validate()) { foreach ($form->getData('blocks') as $block) { $blockPlugin = new CustomBlockPlugin($block, $this->getName()); // Default the block to being enabled if (!is_bool($blockPlugin->getEnabled())) { $blockPlugin->setEnabled(true); } // Default the block to the right sidebar if (!is_numeric($blockPlugin->getBlockContext())) { $blockPlugin->setBlockContext(BLOCK_CONTEXT_RIGHT_SIDEBAR); } } } } else { $form->initData(); } } } if (!isset($editData) && $form->validate()) { $form->execute(); $form->display(); exit; } else { $form->display(); exit; } return true; default: // Unknown management verb assert(false); return false; } }
/** * Register as a block plugin, even though this is a generic plugin. * This will allow the plugin to behave as a block plugin, i.e. to * have layout tasks performed on it. * @param $hookName string The name of the hook being invoked * @param $args array The parameters to the invoked hook */ function callbackLoadCategory($hookName, $args) { $category =& $args[0]; $plugins =& $args[1]; $request =& $this->getRequest(); switch ($category) { case 'blocks': // The system is registering block plugins $this->import('CustomBlockPlugin'); // Ensure that there is a context (journal or press) $context = $request->getContext(); if (!$context) { return false; } // Load the custom blocks we have created $blocks = $this->getSetting($context->getId(), 'blocks'); if (!is_array($blocks)) { break; } // Loop through each custom block and register it $i = 0; foreach ($blocks as $block) { $blockPlugin = new CustomBlockPlugin($block, $this->getName()); // Default the block to being enabled (for newly created blocks) if ($blockPlugin->getEnabled() !== false) { $blockPlugin->setEnabled(true); } // Default the block to the right sidebar (for newly created blocks) if (!is_numeric($blockPlugin->getBlockContext())) { $blockPlugin->setBlockContext(BLOCK_CONTEXT_RIGHT_SIDEBAR); } // Add the plugin to the list of registered plugins $plugins[$blockPlugin->getSeq()][$blockPlugin->getPluginPath() . $i] =& $blockPlugin; $i++; unset($blockPlugin); } break; } return false; }