/**
  * @param \Sonata\PageBundle\CmsManager\CmsManagerInterface $manager
  * @param \Sonata\PageBundle\Model\BlockInterface $block
  * @param \Sonata\PageBundle\Model\PageInterface $page
  * @param null|\Symfony\Component\HttpFoundation\Response $response
  * @return null|string|\Symfony\Component\HttpFoundation\Response
  */
 public function execute(CmsManagerInterface $manager, BlockInterface $block, PageInterface $page, Response $response = null)
 {
     $settings = array_merge($this->getDefaultSettings(), $block->getSettings());
     $response = $this->renderResponse('SonataPageBundle:Block:block_container.html.twig', array('container' => $block, 'manager' => $manager, 'page' => $page, 'settings' => $settings), $response);
     $response->setContent(Mustache::replace($settings['layout'], array('CONTENT' => $response->getContent())));
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * @throws \Exception
  * @param \Sonata\PageBundle\CmsManager\CmsManagerInterface $manager
  * @param \Sonata\PageBundle\Model\BlockInterface $block
  * @param \Sonata\PageBundle\Model\PageInterface $page
  * @param null|\Symfony\Component\HttpFoundation\Response $response
  * @return string
  */
 public function execute(CmsManagerInterface $manager, BlockInterface $block, PageInterface $page, Response $response = null)
 {
     $parameters = (array) json_decode($block->getSetting('parameters'), true);
     $parameters = array_merge($parameters, array('_block' => $block, '_page' => $page));
     $settings = array_merge($this->getDefaultSettings(), (array) $block->getSettings());
     try {
         $actionContent = $this->kernel->render($settings['action'], $parameters);
     } catch (\Exception $e) {
         throw $e;
     }
     $content = Mustache::replace($block->getSetting('layout'), array('CONTENT' => $actionContent));
     return $this->renderResponse('SonataPageBundle:Block:block_core_action.html.twig', array('content' => $content, 'block' => $block, 'page' => $page), $response);
 }
Ejemplo n.º 3
0
 /**
  * @param \Sonata\PageBundle\Model\BlockInterface $block
  * @param \Sonata\PageBundle\Model\PageInterface $page
  * @param null|\Symfony\Component\HttpFoundation\Response $response
  * @return string
  */
 public function execute(CmsManagerInterface $manager, BlockInterface $block, PageInterface $page, Response $response = null)
 {
     // merge settings
     $settings = array_merge($this->getDefaultSettings(), $block->getSettings());
     $feeds = false;
     if ($settings['url']) {
         $options = array('http' => array('user_agent' => 'Sonata/RSS Reader', 'timeout' => 2));
         // retrieve contents with a specific stream context to avoid php errors
         $content = @file_get_contents($settings['url'], false, stream_context_create($options));
         if ($content) {
             // generate a simple xml element
             try {
                 $feeds = new \SimpleXMLElement($content);
                 $feeds = $feeds->channel->item;
             } catch (\Exception $e) {
                 // silently fail error
             }
         }
     }
     return $this->renderResponse('SonataPageBundle:Block:block_core_rss.html.twig', array('feeds' => $feeds, 'block' => $block, 'settings' => $settings), $response);
 }
Ejemplo n.º 4
0
 /**
  * Add children
  *
  * @param \Sonata\PageBundle\Model\BlockInterface $child
  */
 public function addChildren(BlockInterface $child)
 {
     $this->children[] = $child;
     $child->setParent($this);
     $child->setPage($this->getPage());
 }
Ejemplo n.º 5
0
 /**
  * @throws \RuntimeException
  * @param \Sonata\PageBundle\Model\BlockInterface $block
  * @return array|bool
  */
 public function getCacheService(BlockInterface $block)
 {
     if (!$this->hasCacheService($block->getType())) {
         throw new \RuntimeException(sprintf('The block service `%s` referenced in the block `%s` does not exists', $block->getType(), $block->getId()));
     }
     return $this->cacheServices[$block->getType()];
 }
 /**
  * @param \Sonata\PageBundle\CmsManager\CmsManagerInterface $manager
  * @param \Sonata\PageBundle\Model\BlockInterface $block
  * @return void
  */
 public function load(CmsManagerInterface $manager, BlockInterface $block)
 {
     if (is_numeric($block->getSetting('pageId'))) {
         $block->setSetting('pageId', $manager->getPage($block->getSetting('pageId')));
     }
 }
Ejemplo n.º 7
0
 /**
  * @param \Sonata\PageBundle\Model\BlockInterface $block
  * @return array
  */
 public function createBlocks(BlockInterface $block)
 {
     $content = array();
     $content['id'] = $block->getId();
     $content['enabled'] = $block->getEnabled();
     $content['position'] = $block->getPosition();
     $content['settings'] = $block->getSettings();
     $content['type'] = $block->getType();
     $content['created_at'] = $block->getCreatedAt()->format('U');
     $content['updated_at'] = $block->getUpdatedAt()->format('U');
     $content['blocks'] = array();
     foreach ($block->getChildren() as $child) {
         $content['blocks'][] = $this->createBlocks($child);
     }
     return $content;
 }
Ejemplo n.º 8
0
 /**
  * @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
  * @param \Sonata\PageBundle\Model\BlockInterface $block
  * @return
  */
 public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
 {
     if (!$block->getId() && !$block->getType()) {
         return;
     }
     $service = $this->getBlockService($block);
     $service->validateBlock($this, $errorElement, $block);
 }
Ejemplo n.º 9
0
 /**
  * Returns the cache keys for the block
  *
  * @param \Sonata\PageBundle\CmsManager\CmsManagerInterface $manager
  * @param \Sonata\PageBundle\Model\BlockInterface $block
  * @return \Sonata\PageBundle\Cache\CacheElement
  */
 public function getCacheElement(CmsManagerInterface $manager, BlockInterface $block)
 {
     $baseCacheKeys = array('manager' => $manager->getCode(), 'block_id' => $block->getId(), 'page_id' => $block->getPage()->getId(), 'updated_at' => $block->getUpdatedAt()->format('U'));
     return new CacheElement($baseCacheKeys, $block->getTtl());
 }
Ejemplo n.º 10
0
 public function preUpdate(BlockInterface $block)
 {
     $block->setSetting('mediaId', is_object($block->getSetting('mediaId')) ? $block->getSetting('mediaId')->getId() : null);
 }
Ejemplo n.º 11
0
 /**
  * @param CmsManagerInterface $manager
  * @param \Sonata\PageBundle\Model\BlockInterface $block
  * @param \Sonata\PageBundle\Model\PageInterface $page
  * @param null|\Symfony\Component\HttpFoundation\Response $response
  * @return string
  */
 public function execute(CmsManagerInterface $manager, BlockInterface $block, PageInterface $page, Response $response = null)
 {
     $settings = array_merge($this->getDefaultSettings(), $block->getSettings());
     return $this->renderResponse('SonataPageBundle:Block:block_core_text.html.twig', array('block' => $block, 'settings' => $settings), $response);
 }