Ejemplo n.º 1
0
 /**
  * Determine if the block is displayable based on the filter criteria.
  *
  * @param BlockEntity $blockEntity
  * @return boolean
  */
 public function isDisplayable(BlockEntity $blockEntity)
 {
     $request = $this->requestStack->getCurrentRequest();
     if (null === $request) {
         return true;
     }
     $displayable = true;
     $filters = $blockEntity->getFilters();
     foreach ($filters as $filter) {
         switch ($filter['attribute']) {
             case 'query param':
                 $name = $request->query->get($filter['queryParameter']);
                 break;
             case '_route_params':
                 $params = $request->attributes->get('_route_params');
                 $name = isset($params[$filter['queryParameter']]) ? $params[$filter['queryParameter']] : 'kjashdhk11111';
                 // random characters to prevent match
                 break;
             default:
                 $name = $request->attributes->get($filter['attribute']);
         }
         $displayable = $displayable && $this->compare($name, $filter['comparator'], $filter['value']);
     }
     // filter for language/locale
     $language = $blockEntity->getLanguage();
     if (!empty($language)) {
         $displayable = $displayable && $language == $request->getLocale();
     }
     return $displayable;
 }
Ejemplo n.º 2
0
 public function upgradeBkeyToFqClassname(KernelInterface $kernel, BlockEntity $blockEntity)
 {
     $moduleName = $blockEntity->getModule()->getName();
     try {
         $moduleBundle = $kernel->getModule($moduleName);
         $blockClassName = $moduleBundle->getNamespace() . '\\Block\\' . ucwords($blockEntity->getBkey());
         $blockClassName = preg_match('/.*Block$/', $blockClassName) ? $blockClassName : $blockClassName . 'Block';
     } catch (\Exception $e) {
         $moduleBundle = null;
         $blockClassName = '\\' . ucwords($moduleName) . '\\' . 'Block\\' . ucwords($blockEntity->getBkey());
         $blockClassName = preg_match('/.*Block$/', $blockClassName) ? $blockClassName : $blockClassName . 'Block';
         $blockClassNameOld = '\\' . ucwords($moduleName) . '_' . 'Block_' . ucwords($blockEntity->getBkey());
         $blockClassName = class_exists($blockClassName) ? $blockClassName : $blockClassNameOld;
     }
     return "{$moduleName}:{$blockClassName}";
 }
Ejemplo n.º 3
0
 public function setBlock(BlockEntity $block = null)
 {
     if ($this->block !== null) {
         $this->block->removePlacement($this);
     }
     if ($block !== null) {
         $block->addPlacement($this);
     }
     $this->block = $block;
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Create a new block.
  *
  * @param mixed[] $args {
  *      @type string $title       the title of the block
  *      @type string $description the description of the block
  *      @type int    $mid         the module ID of the block
  *      @type string $language    the language of the block
  *      @type int    $bkey        the key of the block
  *
  * @return int|bool block id on success, false on failure.
  *
  * @throws \InvalidArgumentException Thrown if invalid parameters are received in $args
  * @throws AccessDeniedException Thrown if the user doesn't have permission to create the block
  */
 public function create($args)
 {
     // Argument check
     if (!isset($args['title']) || !isset($args['description']) || (!isset($args['mid']) || !is_numeric($args['mid'])) || !isset($args['language']) || !isset($args['collapsable']) || !isset($args['defaultstate']) || !isset($args['bkey'])) {
         throw new \InvalidArgumentException(__('Invalid arguments array received'));
     }
     // Security check
     if (!System::isInstalling() && !SecurityUtil::checkPermission('ZikulaBlocksModule::', "{$args['bkey']}:{$args['title']}:", ACCESS_ADD)) {
         throw new AccessDeniedException();
     }
     // optional arguments
     if (!isset($args['content']) || !is_string($args['content'])) {
         $args['content'] = '';
     }
     $blockData = array('title' => $args['title'], 'description' => $args['description'], 'language' => $args['language'], 'collapsable' => $args['collapsable'], 'module' => $this->entityManager->getReference('Zikula\\ExtensionsModule\\Entity\\ExtensionEntity', $args['mid']), 'defaultstate' => $args['defaultstate'], 'bkey' => $args['bkey'], 'content' => $args['content']);
     $block = new BlockEntity();
     $block->merge($blockData);
     $this->entityManager->persist($block);
     // insert block positions for this block
     if (isset($args['positions']) && is_array($args['positions'])) {
         foreach ($args['positions'] as $position) {
             $placement = new BlockPlacementEntity();
             $placement->setPosition($this->entityManager->getReference('ZikulaBlocksModule:BlockPositionEntity', $position));
             $placement->setBlock($block);
             $this->entityManager->persist($placement);
         }
     }
     $this->entityManager->flush();
     return $block->getBid();
 }
Ejemplo n.º 5
0
 /**
  * @deprecated
  * @return int
  */
 public function getBid()
 {
     return $this->block->getBid();
 }
Ejemplo n.º 6
0
 /**
  * Get the html output from the block's `modify` method.
  *
  * @deprecated This method is not required in Core-2.0. Simply use
  *   `$output = $blockClassInstance->modify($request, $blockEntity->getContent());`
  * @param $blockClassInstance
  * @param BlockEntity $blockEntity
  * @param Request $request
  * @return mixed|string
  */
 private function getBlockModifyOutput($blockClassInstance, BlockEntity $blockEntity, Request $request)
 {
     $output = '';
     if ($blockClassInstance instanceof BlockControllerInterface) {
         $output = $blockClassInstance->modify($request, $blockEntity->getContent());
     } elseif ($blockClassInstance instanceof \Zikula_Controller_AbstractBlock) {
         // @todo remove this BC at Core-2.0
         $blockInfo = \BlockUtil::getBlockInfo($blockEntity->getBid());
         $blockInfo = $blockInfo ? $blockInfo : ['content' => ''];
         $output = call_user_func([$blockClassInstance, 'modify'], $blockInfo);
     }
     return $output;
 }
Ejemplo n.º 7
0
 private function setUpBlockPlacements()
 {
     $this->blockPlacements = new ArrayCollection();
     $block = new BlockEntity();
     $block->setBid(1);
     $placement = new BlockPlacementEntity();
     $placement->setBlock($block);
     $this->blockPlacements->set(1, $placement);
     $block = new BlockEntity();
     $block->setBid(2);
     $placement = new BlockPlacementEntity();
     $placement->setBlock($block);
     $this->blockPlacements->set(2, $placement);
     $block = new BlockEntity();
     $block->setBid(5);
     $placement = new BlockPlacementEntity();
     $placement->setBlock($block);
     $this->blockPlacements->set(5, $placement);
 }
Ejemplo n.º 8
0
 /**
  * Display one block.
  *
  * @param BlockEntity $block
  * @param string $positionName @deprecated argument. remove at Core-2.0
  * @return string
  */
 public function showBlock(BlockEntity $block, $positionName = '')
 {
     $blockInstance = $this->blockApi->createInstanceFromBKey($block->getBkey());
     $legacy = false;
     $content = '';
     if ($blockInstance instanceof BlockControllerInterface) {
         $content = $blockInstance->display($block->getContent());
     } elseif ($blockInstance instanceof \Zikula_Controller_AbstractBlock) {
         // @todo remove at Core-2.0
         $legacy = true;
         $args = \BlockUtil::getBlockInfo($block->getBid());
         $args['position'] = $positionName;
         $content = $blockInstance->display($args);
     }
     if (!$legacy) {
         if (null !== ($moduleInstance = $this->extensionApi->getModuleInstanceOrNull($block->getModule()->getName()))) {
             // @todo can remove check for null at Core-2.0
             // add module stylesheet to page - legacy blocks load stylesheets automatically on ModUtil::load()
             $moduleInstance->addStylesheet();
         }
     }
     return $this->themeEngine->wrapBlockContentInTheme($content, $block->getTitle(), $block->getBlocktype(), $block->getBid(), $positionName, $legacy);
 }
Ejemplo n.º 9
0
 /**
  * Add default block data for new installs
  * This is called after a complete installation since the blocks
  * need to be populated with module id's which are only available
  * once the install has been completed
  */
 public function defaultdata()
 {
     // create the default block positions - left, right and center for the traditional 3 column layout
     $positions = ['left' => $this->__('Left blocks'), 'right' => $this->__('Right blocks'), 'center' => $this->__('Center blocks'), 'search' => $this->__('Search block'), 'header' => $this->__('Header block'), 'footer' => $this->__('Footer block'), 'topnav' => $this->__('Top navigation block'), 'bottomnav' => $this->__('Bottom navigation block')];
     foreach ($positions as $name => $description) {
         $positions[$name] = new BlockPositionEntity();
         $positions[$name]->setName($name);
         $positions[$name]->setDescription($description);
         $this->entityManager->persist($positions[$name]);
     }
     $this->entityManager->flush();
     // build the menu content
     $languages = ZLanguage::getInstalledLanguages();
     $saveLanguage = ZLanguage::getLanguageCode();
     $menucontent = array();
     $topnavcontent = array();
     foreach ($languages as $lang) {
         ZLanguage::setLocale($lang);
         ZLanguage::bindCoreDomain();
         $menucontent['displaymodules'] = '0';
         $menucontent['stylesheet'] = 'extmenu.css';
         $menucontent['template'] = 'Block/Extmenu/extmenu.tpl';
         $menucontent['blocktitles'][$lang] = $this->__('Main menu');
         // insert the links
         $menucontent['links'][$lang][] = array('name' => $this->__('Home'), 'url' => '{homepage}', 'title' => $this->__("Go to the home page"), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $menucontent['links'][$lang][] = array('name' => $this->__('Administration'), 'url' => '{Admin:admin:adminpanel}', 'title' => $this->__('Go to the site administration'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $menucontent['links'][$lang][] = array('name' => $this->__('My Account'), 'url' => '{ZikulaUsersModule}', 'title' => $this->__('Go to your account panel'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $menucontent['links'][$lang][] = array('name' => $this->__('Log out'), 'url' => '{ZikulaUsersModule:user:logout}', 'title' => $this->__('Log out of this site'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $menucontent['links'][$lang][] = array('name' => $this->__('Site search'), 'url' => '{ZikulaSearchModule}', 'title' => $this->__('Search this site'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $topnavcontent['displaymodules'] = '0';
         $topnavcontent['stylesheet'] = 'extmenu.css';
         $topnavcontent['template'] = 'Block/Extmenu/topnav.tpl';
         $topnavcontent['blocktitles'][$lang] = $this->__('Top navigation');
         // insert the links
         $topnavcontent['links'][$lang][] = array('name' => $this->__('Home'), 'url' => '{homepage}', 'title' => $this->__("Go to the site's home page"), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $topnavcontent['links'][$lang][] = array('name' => $this->__('My Account'), 'url' => '{ZikulaUsersModule}', 'title' => $this->__('Go to your account panel'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $topnavcontent['links'][$lang][] = array('name' => $this->__('Site search'), 'url' => '{ZikulaSearchModule}', 'title' => $this->__('Search this site'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
     }
     ZLanguage::setLocale($saveLanguage);
     $searchcontent = ['displaySearchBtn' => 1, 'active' => array('ZikulaUsersModule' => 1)];
     $hellomessage = $this->__('<p><a href="http://zikula.org/">Zikula</a> is a content management system (CMS) and application framework. It is secure and stable, and is a good choice for sites with a large volume of traffic.</p><p>With Zikula:</p><ul><li>you can customise all aspects of the site\'s appearance through themes, with support for CSS style sheets, JavaScript, Flash and all other modern web development technologies;</li><li>you can mark content as being suitable for either a single language or for all languages, and can control all aspects of localisation and internationalisation of your site;</li><li>you can be sure that your pages will display properly in all browsers, thanks to Zikula\'s full compliance with W3C HTML standards;</li><li>you get a standard application-programming interface (API) that lets you easily augment your site\'s functionality through modules, blocks and other extensions;</li><li>you can get help and support from the Zikula community of webmasters and developers at <a href="http://www.zikula.org">zikula.org</a>.</li></ul><p>Enjoy using Zikula!</p><p><strong>The Zikula team</strong></p><p><em>Note: Zikula is Free Open Source Software (FOSS) licensed under the GNU General Public License.</em></p>');
     $blocks = [];
     $blocksModuleEntity = $this->entityManager->getRepository('\\Zikula\\ExtensionsModule\\Entity\\ExtensionEntity')->findOneBy(['name' => 'ZikulaBlocksModule']);
     $searchModuleEntity = $this->entityManager->getRepository('\\Zikula\\ExtensionsModule\\Entity\\ExtensionEntity')->findOneBy(['name' => 'ZikulaSearchModule']);
     $usersModuleEntity = $this->entityManager->getRepository('\\Zikula\\ExtensionsModule\\Entity\\ExtensionEntity')->findOneBy(['name' => 'ZikulaUsersModule']);
     $blocks[] = ['bkey' => 'ZikulaBlocksModule:\\Zikula\\BlocksModule\\Block\\ExtmenuBlock', 'blocktype' => 'Extmenu', 'language' => '', 'module' => $blocksModuleEntity, 'title' => $this->__('Main menu'), 'description' => $this->__('Main menu'), 'content' => $menucontent, 'position' => $positions['left']];
     $blocks[] = ['bkey' => 'ZikulaSearchModule:\\Zikula\\SearchModule\\Block\\SearchBlock', 'blocktype' => 'Search', 'language' => '', 'module' => $searchModuleEntity, 'title' => $this->__('Search box'), 'description' => $this->__('Search block'), 'content' => $searchcontent, 'position' => $positions['search']];
     $blocks[] = ['bkey' => 'ZikulaBlocksModule:\\Zikula\\BlocksModule\\Block\\HtmlBlock', 'blocktype' => 'Html', 'language' => '', 'module' => $blocksModuleEntity, 'title' => $this->__("This site is powered by Zikula!"), 'description' => $this->__('HTML block'), 'content' => $hellomessage, 'position' => $positions['center']];
     $blocks[] = ['bkey' => 'ZikulaUsersModule:\\Zikula\\UsersModule\\Block\\LoginBlock', 'blocktype' => 'Login', 'language' => '', 'module' => $usersModuleEntity, 'title' => $this->__('User log-in'), 'description' => $this->__('Login block'), 'position' => $positions['right']];
     $blocks[] = ['bkey' => 'ZikulaBlocksModule:\\Zikula\\BlocksModule\\Block\\ExtmenuBlock', 'blocktype' => 'Extmenu', 'language' => '', 'module' => $blocksModuleEntity, 'title' => $this->__('Top navigation'), 'description' => $this->__('Theme navigation'), 'content' => $topnavcontent, 'position' => $positions['topnav']];
     foreach ($blocks as $block) {
         $blockEntity = new BlockEntity();
         $position = $block['position'];
         unset($block['position']);
         $blockEntity->merge($block);
         $this->entityManager->persist($blockEntity);
         $placement = new BlockPlacementEntity();
         $placement->setBlock($blockEntity);
         $placement->setPosition($position);
         $this->entityManager->persist($placement);
     }
     $this->entityManager->flush();
     return;
 }