Пример #1
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();
 }
Пример #2
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);
 }
Пример #3
0
 /**
  * @Route("/ajax/changeorder", options={"expose"=true, "i18n"=false})
  * @Method("POST")
  *
  * Change the block order.
  *
  * @param Request $request
  *
  *  blockorder array of sorted blocks (value = block id)
  *  position int zone id
  *
  * @return JsonResponse|ForbiddenResponse true or Ajax error
  */
 public function changeBlockOrderAction(Request $request)
 {
     if (!$this->hasPermission('ZikulaBlocksModule::', '::', ACCESS_ADMIN)) {
         return new ForbiddenResponse($this->__('No permission for this action.'));
     }
     $blockorder = $request->request->get('blockorder', []);
     // [7, 1]
     $position = $request->request->get('position');
     // 1
     $em = $this->getDoctrine()->getManager();
     // remove all block placements from this position
     $query = $em->createQueryBuilder()->delete()->from('ZikulaBlocksModule:BlockPlacementEntity', 'p')->where('p.position = :position')->setParameter('position', $position)->getQuery();
     $query->getResult();
     // add new block positions
     foreach ((array) $blockorder as $order => $bid) {
         $placement = new BlockPlacementEntity();
         $placement->setPosition($em->getReference('ZikulaBlocksModule:BlockPositionEntity', $position));
         $placement->setBlock($em->getReference('ZikulaBlocksModule:BlockEntity', $bid));
         $placement->setSortorder($order);
         $em->persist($placement);
     }
     $em->flush();
     return new JsonResponse(['result' => true]);
 }
Пример #4
0
 /**
  * Set BlockPlacementsEntity from provided ArrayCollection of positionEntity
  * requires
  *   cascade={"remove, "persist"}
  *   orphanRemoval=true
  *   on the association of $this->placements
  * @param ArrayCollection $positions
  */
 public function setPositions(ArrayCollection $positions)
 {
     // remove placements and skip existing placements.
     foreach ($this->placements as $placement) {
         if (!$positions->contains($placement->getPosition())) {
             $this->placements->removeElement($placement);
         } else {
             $positions->removeElement($placement->getPosition());
             // remove from positions to add.
         }
     }
     // add new placements
     foreach ($positions as $position) {
         $placement = new BlockPlacementEntity();
         $placement->setPosition($position);
         // sortorder is irrelevant at this stage.
         $placement->setBlock($this);
         // auto-adds placement
     }
 }
Пример #5
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;
 }