public static function onRender(Event $event)
 {
     $renderer = $event->getEventArgs();
     $application = $event->getDispatcher()->getApplication();
     $em = $application->getEntityManager();
     $content = $renderer->getObject();
     $links = $content->getParamValue('link');
     $link = ['url' => '', 'title' => 'Visit', 'target' => '_self'];
     if (!empty($links)) {
         $links = reset($links);
         if (isset($links['pageUid']) && !empty($links['pageUid'])) {
             $page = $em->getRepository('BackBee\\NestedNode\\Page')->find($links['pageUid']);
             if ($page !== null) {
                 $link['url'] = $renderer->getUri($page->getUrl());
             }
         }
         if (empty($link['url']) && isset($links['url'])) {
             $link['url'] = $links['url'];
         }
         if (isset($links['title'])) {
             $link['title'] = $links['title'];
         }
         if (isset($links['target'])) {
             $link['target'] = $links['target'];
         }
     }
     $renderer->assign('link', $link);
 }
Example #2
0
 /**
  * Occur on nestednode.page.onflush events.
  *
  * @param \BackBee\Event\Event $event
  */
 public static function onFlushPage(Event $event)
 {
     if (true === self::$onFlushPageAlreadyCalled) {
         return;
     }
     $page = $event->getTarget();
     if (!$page instanceof Page) {
         return;
     }
     $application = $event->getApplication();
     $em = $application->getEntityManager();
     $uow = $em->getUnitOfWork();
     if ($uow->isScheduledForDelete($page)) {
         return;
     }
     if (null === ($metadata_config = $application->getConfig()->getSection('metadata'))) {
         return;
     }
     if (null === ($metadata = $page->getMetaData())) {
         $metadata = new \BackBee\MetaData\MetaDataBag($metadata_config, $page);
     } else {
         $metadata->update($metadata_config, $page);
     }
     $page->setMetaData($metadata->compute($page));
     if ($uow->isScheduledForInsert($page) || $uow->isScheduledForUpdate($page)) {
         $uow->recomputeSingleEntityChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page);
     } elseif (!$uow->isScheduledForDelete($page)) {
         $uow->computeChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page);
     }
     self::$onFlushPageAlreadyCalled = true;
 }
Example #3
0
 /**
  * Occurs on event ``bbapplication.init`` to dump application container if debug mode is false.
  *
  * @param Event $event
  */
 public static function onApplicationInit(Event $event)
 {
     $application = $event->getTarget();
     $container = $application->getContainer();
     if (false === $application->isDebugMode() && false === $container->isRestored()) {
         $containerFilename = $container->getParameter('container.filename');
         $containerDir = $container->getParameter('container.dump_directory');
         if (false === is_dir($containerDir) && false === @mkdir($containerDir, 0755)) {
             throw new CannotCreateContainerDirectoryException($containerDir);
         }
         if (false === is_writable($containerDir)) {
             throw new ContainerDirectoryNotWritableException($containerDir);
         }
         $dumper = new PhpArrayDumper($container);
         $dump = $dumper->dump(array('do_compile' => true));
         $container_proxy = new ContainerProxy();
         $dump = unserialize($dump);
         $container_proxy->init($dump);
         $container_proxy->setParameter('services_dump', serialize($dump['services']));
         $container_proxy->setParameter('is_compiled', $dump['is_compiled']);
         file_put_contents($containerDir . DIRECTORY_SEPARATOR . $containerFilename . '.php', (new PhpDumper($container_proxy))->dump(array('class' => $containerFilename, 'base_class' => 'BackBee\\DependencyInjection\\ContainerProxy')));
     } elseif (true === $application->isDebugMode() && false === $container->isRestored()) {
         $container->compile();
     }
 }
 /**
  * occurs on `bbapplication.start`.
  *
  * @param Event $event
  */
 public static function onApplicationStart(Event $event)
 {
     $application = $event->getTarget();
     $twig_adapter = $application->getRenderer()->getAdapter('twig');
     foreach ($application->getContainer()->findTaggedServiceIds('twig.extension') as $id => $datas) {
         $twig_adapter->addExtension($application->getContainer()->get($id));
     }
 }
Example #5
0
 /**
  * Occurs on `bbapplication.stop` event to stop every started bundles.
  *
  * @param Event $event
  */
 public static function onApplicationStop(Event $event)
 {
     $container = $event->getTarget()->getContainer();
     foreach (array_keys($container->findTaggedServiceIds('bundle')) as $bundleId) {
         if ($container->hasInstanceOf($bundleId)) {
             $container->get($bundleId)->stop();
         }
     }
 }
Example #6
0
 /**
  * @param \BackBee\Event\Event $event
  */
 public function onPostLoad(Event $event)
 {
     $page = $event->getTarget();
     if (!$page instanceof Page) {
         return;
     }
     $isBbSessionActive = $this->_application->getBBUserToken() === null;
     $page->setUseUrlRedirect($isBbSessionActive);
 }
Example #7
0
 /**
  * occurs on `bbapplication.init`.
  *
  * @param Event $event
  */
 public static function onApplicationReady(Event $event)
 {
     $app = $event->getTarget();
     $twigAdapter = $app->getRenderer()->getAdapter('twig');
     if (null === $twigAdapter) {
         return;
     }
     foreach ($app->getContainer()->findTaggedServiceIds('twig.extension') as $id => $data) {
         $twigAdapter->addExtension($app->getContainer()->get($id));
     }
 }
Example #8
0
 /**
  * Occur on site.layout.postremove events.
  *
  * @access public
  *
  * @param Event $event
  */
 public static function onAfterRemove(Event $event)
 {
     $layout = $event->getTarget();
     if (!is_a($layout, 'BackBee\\Site\\Layout')) {
         return;
     }
     $dispatcher = $event->getDispatcher();
     if (null !== $dispatcher->getApplication()) {
         $dispatcher->getApplication()->getEntityManager()->getRepository('BackBee\\Site\\Layout')->removeThumbnail($layout, $dispatcher->getApplication());
     }
     $dispatcher->getApplication()->getRenderer()->removeLayout($layout);
 }
 public static function onPreRenderTwitter(Event $event)
 {
     $renderer = $event->getEventArgs();
     self::$application = $event->getDispatcher()->getApplication();
     $config = self::getSocialConfig('twitter');
     $content = $renderer->getObject();
     $widgetId = $content->getParamValue('widget_id');
     if (empty($widgetId)) {
         if (null !== $config && isset($config['widget_id'])) {
             $widgetId = $config['widget_id'];
         }
     }
     $renderer->assign('widget_id', $widgetId);
 }
 public static function onPostCategoryCall(Event $event)
 {
     $response = $event->getResponse();
     $entityManager = $event->getApplication()->getEntityManager();
     $user = $event->getApplication()->getBBUserToken()->getUser();
     $favoriteCategory = self::getFavoriteCategory($entityManager, $user->getId());
     if (empty($favoriteCategory['contents'])) {
         $favoriteCategory = self::getDefaultFavoriteCategory($entityManager, $event->getApplication()->getSite()->getUid(), $favoriteCategory);
     }
     $categories = json_decode($response->getContent(), true);
     /* the new category has been pushed on top of class content categories */
     array_unshift($categories, $favoriteCategory);
     $response->setContent(json_encode($categories, true));
 }
 public static function onRender(Event $event)
 {
     self::$renderer = $event->getEventArgs();
     self::$application = self::$renderer->getApplication();
     self::$em = self::$application->getEntityManager();
     $content = self::$renderer->getObject();
     $parentNode = self::getParentNode($content->getParamValue('parent_node'));
     $selector = ['parentnode' => [$parentNode !== null ? $parentNode->getUid() : null]];
     $contents = self::$em->getRepository('BackBee\\ClassContent\\AbstractClassContent')->getSelection($selector, in_array('multipage', $content->getParamValue('multipage')), in_array('recursive', $content->getParamValue('recursive')), (int) $content->getParamValue('start'), (int) $content->getParamValue('limit'), self::$application->getBBUserToken() === null, false, (array) $content->getParamValue('content_to_show'), (int) $content->getParamValue('delta'));
     $count = $contents instanceof Paginator ? $contents->count() : count($contents);
     self::$renderer->assign('contents', $contents);
     self::$renderer->assign('nbContents', $count);
     self::$renderer->assign('parentNode', $parentNode);
 }
 public static function onUserCreated(Event $event)
 {
     $application = $event->getDispatcher()->getApplication();
     $site = $application->getSite();
     $user = $event->getTarget();
     if ($user instanceof User && $site instanceof Site) {
         $body = $application->getRenderer()->partial('Email/NewUser.twig', ['user' => $user, 'site_name' => $site->getLabel(), 'home_link' => $site->getServerName()]);
         $message = static::buildMessage($application->getSecurityContext()->getToken()->getUser(), $user, $body, $application->getSite());
         if (null !== $application->getMailer()) {
             $application->getMailer()->send($message);
         } else {
             throw new \RuntimeException('Mailer not available');
         }
     }
 }
 /**
  * Occur on nestednode.page.onflush events.
  *
  * @param \BackBee\Event\Event $event
  */
 public static function onFlushPage(Event $event)
 {
     $page = $event->getTarget();
     if (!$page instanceof Page) {
         return;
     }
     $maincontent = $event->getEventArgs();
     if (!$maincontent instanceof AbstractClassContent) {
         $maincontent = null;
     }
     $dispatcher = $event->getDispatcher();
     $application = $dispatcher->getApplication();
     if (self::updateUrl($application, $page, $maincontent)) {
         $descendants = $application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getDescendants($page, 1);
         foreach ($descendants as $descendant) {
             self::updateUrl($application, $descendant);
         }
     }
 }
 /**
  * Creates an instance of BundleInstallUpdateEvent.
  *
  * @param  BundleInterface $target
  * @param  mixed           $eventArgs
  * @throws \InvalidArgumentException if the provided target does not implement BackBee\Bundle\BundleInterface
  */
 public function __construct($target, $eventArgs = null)
 {
     if (!$target instanceof BundleInterface) {
         throw new \InvalidArgumentException('Target of bundle update or action event must be instance of BackBee\\Bundle\\BundleInterface');
     }
     parent::__construct($target, $eventArgs);
     $this->bundle = $target;
     $this->forced = isset($eventArgs['force']) ? (bool) $eventArgs['force'] : false;
     $this->logs = isset($eventArgs['logs']) ? (array) $eventArgs['logs'] : [];
 }
 public static function onRender(Event $event)
 {
     $renderer = $event->getEventArgs();
     $application = $event->getDispatcher()->getApplication();
     $content = $renderer->getObject();
     $tag = null;
     $url = '#';
     $mainNode = $content->getMainNode();
     if ($mainNode !== null) {
         $url = $renderer->getUri($mainNode->getUrl());
         $parentNode = $mainNode->getParent();
         if (null !== $parentNode) {
             $altTitle = $parentNode->getAltTitle();
             $tag = !empty($altTitle) ? $altTitle : $parentNode->getTitle();
         }
     }
     $renderer->assign('tag', $tag);
     $renderer->assign('url', $url);
 }
Example #16
0
 public static function onRender(Event $event)
 {
     $dispatcher = $event->getDispatcher();
     $renderer = $event->getEventArgs();
     $renderer->assign('keyword', null);
     if (null !== $dispatcher) {
         $application = $dispatcher->getApplication();
         if (null === $application) {
             return;
         }
         $keywordloaded = $event->getTarget();
         if (!is_a($renderer, 'BackBee\\Renderer\\AbstractRenderer')) {
             return;
         }
         $keyWord = $application->getEntityManager()->find('BackBee\\NestedNode\\KeyWord', $keywordloaded->value);
         if (!is_null($keyWord)) {
             $renderer->assign('keyword', $keyWord);
         }
     }
 }
Example #17
0
 /**
  * Create an instance of RendererEvent.
  *
  * @param mixed $target
  * @param mixed $arguments
  */
 public function __construct($target, $arguments = null)
 {
     parent::__construct($target, $arguments);
     $this->render = null;
     if (is_array($arguments)) {
         $this->renderer =& $arguments[0];
         $this->render =& $arguments[1];
     } else {
         $this->renderer =& $arguments;
     }
 }
Example #18
0
 /**
  * Occur on nestednode.page.onflush events.
  *
  * @param Event $event
  */
 public static function onFlushPage(Event $event)
 {
     if (self::$onFlushPageAlreadyCalled) {
         return;
     }
     $page = $event->getTarget();
     if (!$page instanceof Page) {
         return;
     }
     $application = $event->getApplication();
     $em = $application->getEntityManager();
     $uow = $em->getUnitOfWork();
     if ($uow->isScheduledForDelete($page)) {
         return;
     }
     $metadata = $application->getContainer()->get('nestednode.metadata.resolver')->resolve($page);
     $page->setMetaData($metadata);
     if ($uow->isScheduledForInsert($page) || $uow->isScheduledForUpdate($page)) {
         $uow->recomputeSingleEntityChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page);
     } elseif (!$uow->isScheduledForDelete($page)) {
         $uow->computeChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page);
     }
     self::$onFlushPageAlreadyCalled = true;
 }
Example #19
0
 /**
  * Occur on nestednode.page.preupdate events.
  *
  * @access public
  *
  * @param Event $event
  */
 public static function onPreUpdate(Event $event)
 {
     $page = $event->getTarget();
     $eventArgs = $event->getEventArgs();
     if ($eventArgs instanceof PreUpdateEventArgs) {
         if ($eventArgs->hasChangedField('_workflow_state')) {
             $old = $eventArgs->getOldValue('_workflow_state');
             $new = $eventArgs->getNewValue('_workflow_state');
             if (null !== $new && null !== ($listener = $new->getListenerInstance())) {
                 $listener->switchOnState($event);
             }
             if (null !== $old && null !== ($listener = $old->getListenerInstance())) {
                 $listener->switchOffState($event);
             }
         }
         if ($eventArgs->hasChangedField('_state')) {
             if (!($eventArgs->getOldValue('_state') & Page::STATE_ONLINE) && $eventArgs->getNewValue('_state') & Page::STATE_ONLINE) {
                 $event->getDispatcher()->triggerEvent('putonline', $page);
             } elseif ($eventArgs->getOldValue('_state') & Page::STATE_ONLINE && !($eventArgs->getNewValue('_state') & Page::STATE_ONLINE)) {
                 $event->getDispatcher()->triggerEvent('putoffline', $page);
             }
         }
     }
 }
 /**
  * Returns the current application.
  *
  * @param \BackBee\Event\Event $event
  *
  * @return \BackBee\BBApplication
  */
 private static function _getApplication(Event $event)
 {
     if (null === self::$_application) {
         if (null !== $event->getDispatcher()) {
             self::$_application = $event->getDispatcher()->getApplication();
         }
     }
     return self::$_application;
 }
Example #21
0
 /**
  * Create a new instance of PreRequestEvent.
  *
  * @param Request $request
  */
 public function __construct(Request $request)
 {
     parent::__construct($request);
 }
Example #22
0
 public static function onPrerenderContent(Event $event)
 {
     $dispatcher = $event->getDispatcher();
     if (null === ($application = $dispatcher->getApplication())) {
         return;
     }
     if (null === ($token = $application->getBBUserToken())) {
         return;
     }
     $renderer = $event->getEventArgs();
     if (!is_a($renderer, 'BackBee\\Renderer\\AbstractRenderer')) {
         return;
     }
     $content = $renderer->getObject();
     if (!is_a($content, 'BackBee\\ClassContent\\AbstractClassContent')) {
         return;
     }
     $em = $application->getEntityManager();
     if (null !== ($revision = $em->getRepository('BackBee\\ClassContent\\Revision')->getDraft($content, $token))) {
         $content->setDraft($revision);
         $application->debug(sprintf('Revision found for `%s` content and `%s` user', $content->getUid(), $token->getUsername()));
     }
     if (!$content instanceof ContentSet) {
         foreach ($content->getData() as $key => $subcontent) {
             if (null === $subcontent) {
                 $contenttype = $content->getAcceptedType($key);
                 if (0 === strpos($contenttype, 'BackBee\\ClassContent\\')) {
                     if (null === $content->getDraft()) {
                         $revision = $em->getRepository('BackBee\\ClassContent\\Revision')->getDraft($content, $token, true);
                         $content->setDraft($revision);
                     }
                     $content->{$key} = new $contenttype();
                 }
             }
         }
     }
 }
 public static function onPostCall(Event $event)
 {
     $response = $event->getResponse();
     if ($response->headers->get('content-type') === 'text/html') {
         return;
     }
     $application = $event->getApplication();
     $renderer = $application->getRenderer();
     $content = json_decode($response->getContent());
     $result = false;
     if ($content instanceof \StdClass) {
         if (isset($content->type) && isset($content->parameters)) {
             if (isset($content->parameters->rendermode)) {
                 $result = true;
             }
         }
     }
     if (!$result) {
         return;
     }
     $rendermodeParam = $content->parameters->rendermode;
     $classname = AbstractClassContent::getClassnameByContentType($content->type);
     $modes = ['default' => 'Default mode'];
     foreach ($renderer->getAvailableRenderMode(new $classname()) as $mode) {
         $modes[$mode] = ucfirst(str_replace('_', ' ', $mode));
     }
     $rendermodeParam->options = $modes;
     $response->setContent(json_encode($content));
 }
Example #24
0
 /**
  * Occur on nestednode.page.preupdate events and nestednode.section.preupdate.
  *
  * @access public
  *
  * @param Event $event
  */
 public static function onFlushPage(Event $event)
 {
     $em = $event->getApplication()->getEntityManager();
     $uow = $em->getUnitOfWork();
     $page = $event->getTarget();
     if ($uow->isScheduledForInsert($page) && $page->getParent() !== null && $page->getState() < 4) {
         self::setSectionHasChildren($em, $page->getParent()->getSection(), +1);
     }
 }
Example #25
0
 /**
  * occurs on `service.tagged.test`.
  *
  * @param Event $event
  */
 public function onGetServiceTaggedTestEvent(Event $event)
 {
     $this->foo = 'foo';
     $datetime = $event->getTarget();
     $datetime->setTimestamp(ContainerTest::NEW_DATE_WITH_TAG_VALUE);
 }
Example #26
0
 /**
  * @param Event $event
  */
 public function onGetServiceConfig(Event $event)
 {
     if (true === $this->application->isStarted()) {
         $config = $event->getTarget();
         if (null !== ($override_site = $config->getRawSection('override_site'))) {
             if (array_key_exists($this->application->getSite()->getUid(), $override_site)) {
                 foreach ($override_site[$this->application->getSite()->getUid()] as $section => $data) {
                     $config->setSection($section, $data, true);
                 }
             }
         }
         $this->application->getContainer()->getDefinition($event->getArgument('id'))->clearTag('config_per_site');
     }
 }
 /**
  * Occurs on event ``bbapplication.init`` to set AbstractContent::$ignoreUnknownClassname according to bbapp parameters.
  *
  * @param Event $event
  */
 public static function onApplicationInit(Event $event)
 {
     $application = $event->getTarget();
     $container = $application->getContainer();
     if ($container->hasParameter('bbapp.classcontent.exception_on_unknown_classname')) {
         $parameter = $container->getParameter('bbapp.classcontent.exception_on_unknown_classname');
     } else {
         $parameter = true;
     }
     if ('debug' === strtolower($parameter)) {
         AbstractClassContent::throwExceptionOnUnknownClassname($application->isDebugMode());
     } else {
         AbstractClassContent::throwExceptionOnUnknownClassname($parameter);
     }
 }
Example #28
0
 /**
  * Clears cached data associated to the page to be flushed.
  *
  * @param \BackBee\Event\Event $event
  */
 public function onFlushPage(Event $event)
 {
     // Checks if page caching is available
     $this->object = $event->getTarget();
     if (false === $this->object instanceof Page || false === $this->checkCachePageEvent(false)) {
         return;
     }
     if (true === $this->page_cache_deletion_done) {
         return;
     }
     $pages = ScheduledEntities::getScheduledEntityUpdatesByClassname($this->application->getEntityManager(), 'BackBee\\NestedNode\\Page');
     if (0 === count($pages)) {
         return;
     }
     $page_uids = array();
     foreach ($pages as $page) {
         $page_uids[] = $page->getUid();
     }
     $this->cache_page->removeByTag($page_uids);
     $this->page_cache_deletion_done = true;
     $this->application->debug(sprintf('Remove cache for `%s(%s)`.', get_class($this->object), implode(', ', $page_uids)));
 }
Example #29
0
 /**
  * Create a new instance of PostResponseEvent.
  *
  * @param Response $response
  * @param Request  $request
  */
 public function __construct(Response $response, Request $request)
 {
     parent::__construct($response, $request);
     $this->request = $request;
 }