Ejemplo n.º 1
0
 /**
  * returns the container of current dispatcher (try to get it application if current dispatcher don't have it).
  *
  * @return mixed null if no container has been found, else the container
  */
 private function getContainer()
 {
     if (null === $this->container && null !== $this->application) {
         $this->container = $this->application->getContainer();
     }
     return $this->container;
 }
Ejemplo n.º 2
0
 public function rssAction($uri = null)
 {
     if (null === $this->application) {
         throw new FrontControllerException('A valid BackBee application is required.', FrontControllerException::INTERNAL_ERROR);
     }
     if (false === $this->application->getContainer()->has('site')) {
         throw new FrontControllerException('A BackBee\\Site instance is required.', FrontControllerException::INTERNAL_ERROR);
     }
     $site = $this->application->getContainer()->get('site');
     if (false !== ($ext = strrpos($uri, '.'))) {
         $uri = substr($uri, 0, $ext);
     }
     if ('_root_' == $uri) {
         $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getRoot($site);
     } else {
         $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->findOneBy(array('_site' => $site, '_url' => '/' . $uri, '_state' => Page::getUndeletedStates()));
     }
     try {
         $this->application->info(sprintf('Handling URL request `rss%s`.', $uri));
         $response = new Response($this->application->getRenderer()->render($page, 'rss', null, 'rss.phtml', false));
         $response->headers->set('Content-Type', 'text/xml');
         $response->setClientTtl(15);
         $response->setTtl(15);
         $this->send($response);
     } catch (\Exception $e) {
         $this->defaultAction('/rss/' . $uri);
     }
 }
 /**
  * Update de la table user
  */
 private function updateUsers($userRights, $input)
 {
     if (!is_array($userRights)) {
         return;
     }
     if (!$input->getOption('user_name') || !$input->getOption('user_password') || !$input->getOption('user_email')) {
         return;
     }
     if (null === ($user = $this->em->getRepository('BackBee\\Security\\User')->findOneBy(array('_login' => $input->getOption('user_name'))))) {
         $encoderFactory = $this->bbapp->getContainer()->get('security.context')->getEncoderFactory();
         $user = new User($input->getOption('user_name'));
         $encoder = $encoderFactory->getEncoder($user);
         $user->setPassword($encoder->encodePassword($input->getOption('user_password'), ''))->setEmail($input->getOption('user_email'))->setLastname($input->getOption('user_firstname'))->setFirstname($input->getOption('user_lastname'))->setApiKeyEnabled(true)->setActivated(true);
         $user->generateRandomApiKey();
         $user->setApiKeyEnabled(true);
         $this->em->persist($user);
         $this->em->flush($user);
     }
     if ($input->getOption('user_group')) {
         if (null !== ($group = $this->em->getRepository('BackBee\\Security\\Group')->findOneBy(array('_name' => $input->getOption('user_group'))))) {
             if (false === $group->getUsers()->indexOf($user)) {
                 $group->addUser($user);
                 $this->em->persist($group);
                 $this->em->flush($group);
             }
         } else {
             $this->writeln(sprintf('Warning: unknown group %s', $input->getOption('user_group')));
         }
     }
     $this->em->persist($user);
     $this->em->flush($user);
     $this->writeln("\t- " . sprintf("|%-20s|", $input->getOption('user_name')) . ": " . $input->getOption('user_password'));
 }
Ejemplo n.º 4
0
 /**
  * Clears cached data associated to the content to be flushed.
  *
  * @param \BackBee\Event\Event $event
  */
 public function onFlushContent(Event $event)
 {
     // Checks if page caching is available
     $this->object = $event->getTarget();
     if (false === $this->object instanceof AbstractClassContent || false === $this->checkCacheContentEvent(false)) {
         return;
     }
     $parent_uids = $this->application->getEntityManager()->getRepository('BackBee\\ClassContent\\Indexes\\IdxContentContent')->getParentContentUids(array($this->object));
     $content_uids = array_diff($parent_uids, $this->content_cache_deletion_done);
     if (0 === count($content_uids)) {
         return;
     }
     $this->cache_content->removeByTag($content_uids);
     $this->content_cache_deletion_done = array_merge($this->content_cache_deletion_done, $content_uids);
     $this->application->debug(sprintf('Remove cache for `%s(%s)`.', get_class($this->object), implode(', ', $content_uids)));
     if (false === $this->application->getContainer()->has('cache.page')) {
         return;
     }
     $cachePage = $this->application->getContainer()->get('cache.page');
     if ($cachePage instanceof CacheExtendedInterface) {
         $node_uids = $this->application->getEntityManager()->getRepository('BackBee\\ClassContent\\Indexes\\IdxContentContent')->getNodeUids($content_uids);
         $cachePage->removeByTag($node_uids);
         $this->application->debug(sprintf('Remove cache for page %s.', implode(', ', $node_uids)));
     }
 }
Ejemplo n.º 5
0
 /**
  * Override Symfony\Component\Translation\Translator to lazy load every catalogs from:
  *     - BackBee\Resources\translations
  *     - PATH_TO_REPOSITORY\Resources\translations
  *     - PATH_TO_CONTEXT_REPOSITORY\Resources\translations.
  *
  * @param BBApplication $application
  * @param string        $locale
  */
 public function __construct(BBApplication $application, $locale)
 {
     parent::__construct($locale);
     // retrieve default fallback from container and set it
     $fallback = $application->getContainer()->getParameter('translator.fallback');
     $this->setFallbackLocales([$fallback]);
     // xliff is recommended by Symfony so we register its loader as default one
     $this->addLoader('xliff', new XliffFileLoader());
     // define in which directory we should looking at to find xliff files
     $dirToLookingAt = array($application->getBBDir() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translations', $application->getRepository() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translations');
     if ($application->getRepository() !== $application->getBaseRepository()) {
         $dirToLookingAt[] = $application->getBaseRepository() . 'Resources' . DIRECTORY_SEPARATOR . 'translations';
     }
     // loop in every directory we should looking at and load catalog from file which match to the pattern
     foreach ($dirToLookingAt as $dir) {
         if (true === is_dir($dir)) {
             foreach (scandir($dir) as $filename) {
                 preg_match('/(.+)\\.(.+)\\.xlf$/', $filename, $matches);
                 if (0 < count($matches)) {
                     $this->addResource('xliff', $dir . DIRECTORY_SEPARATOR . $filename, $matches[2], $matches[1]);
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Returns the static folder path to use.
  *
  * @return string
  */
 protected function getStaticDir()
 {
     $staticDir = $this->app->getContainer()->getParameter('theme.static.dir');
     if (!is_dir($staticDir) && !mkdir($staticDir, 0777, true)) {
         $output->writeln("<error>Unable to read or create the folder '{$staticDir}'</error>");
         exit(1);
     }
     return $staticDir;
 }
Ejemplo n.º 7
0
 /**
  * Create new root page
  *
  * @param  \BackBee\Site\Site       $site       Site object
  * @param  \BackBee\Site\Layout     $layout     Layout object
  *
  * @return \BackBee\NestedNode\Page
  */
 private function createRootPage($site, $layout)
 {
     $pagebuilder = $this->bbapp->getContainer()->get('pagebuilder');
     $pagebuilder->setUid(md5('root-' . $site->getLabel()))->setTitle('Home')->setLayout($layout)->setSite($site)->setUrl('/')->putOnlineAndHidden();
     $page = $pagebuilder->getPage();
     $this->entyMgr->persist($page);
     $this->entyMgr->flush($page);
     return $page;
 }
Ejemplo n.º 8
0
 /**
  * Create new superadmin user
  *
  * @param  string   $login         User name
  * @param  string   $password      User password
  * @param  string   $email         User email
  *
  * @return \BackBee\Security\User   The user object
  */
 private function createUser($login, $password, $email)
 {
     $encoderFactory = $this->bbapp->getContainer()->get('security.context')->getEncoderFactory();
     $adminUser = new \BackBee\Security\User($login, $password, 'SuperAdmin', 'SuperAdmin');
     $adminUser->setApiKeyEnabled(true)->setActivated(true);
     $encoder = $encoderFactory->getEncoder($adminUser);
     $adminUser->setPassword($encoder->encodePassword($password, ''))->setEmail($email)->generateRandomApiKey();
     $this->entyMgr->persist($adminUser);
     $this->entyMgr->flush($adminUser);
     return $adminUser;
 }
Ejemplo n.º 9
0
 /**
  * Hdandles classcontent thumbnail request, returns the right thumbnail if it exists, else the default one.
  *
  * @param string $filename
  *
  * @return Response
  */
 public function getClassContentThumbnailAction($filename)
 {
     $base_folder = $this->application->getContainer()->getParameter('classcontent_thumbnail.base_folder');
     $base_directories = array_map(function ($directory) use($base_folder) {
         return str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $directory . '/' . $base_folder);
     }, $this->application->getResourceDir());
     File::resolveFilepath($filename, null, array('include_path' => $base_directories));
     if (false === file_exists($filename)) {
         $filename = $this->getDefaultClassContentThumbnailFilepath($base_directories);
     }
     if (false === file_exists($filename) || false === is_readable($filename)) {
         $request = $this->application->getRequest();
         throw new FrontControllerException(sprintf('The file `%s` can not be found (referer: %s).', $request->getHost() . '/' . $request->getPathInfo(), $request->server->get('HTTP_REFERER')), FrontControllerException::NOT_FOUND);
     }
     return $this->createResourceResponse($filename);
 }
Ejemplo n.º 10
0
 /**
  * Class constructor.
  *
  * @param \BackBee\BBApplication $application
  */
 public function __construct(BBApplication $application = null)
 {
     $this->application = $application;
     $this->raw_routes = array();
     $this->uri_prefixes = array();
     $container = $application->getContainer();
     if (true === $container->hasParameter('bbapp.routing.image_uri_prefix')) {
         $this->uri_prefixes[self::IMAGE_URL] = $container->getParameter('bbapp.routing.image_uri_prefix');
     }
     if (true === $container->hasParameter('bbapp.routing.media_uri_prefix')) {
         $this->uri_prefixes[self::MEDIA_URL] = $container->getParameter('bbapp.routing.media_uri_prefix');
     }
     if (true === $container->hasParameter('bbapp.routing.resource_uri_prefix')) {
         $this->uri_prefixes[self::RESOURCE_URL] = $container->getParameter('bbapp.routing.resource_uri_prefix');
     }
     $this->is_restored = false;
 }
Ejemplo n.º 11
0
 /**
  * Loads ToolbarBundle and BBCoreJs resources directories into application.
  *
  * @param  BBApplication $application
  * @param  Config        $config
  */
 public static function loadResources(BBApplication $application, Config $config)
 {
     $baseDir = $application->getContainer()->get('bundle.toolbar')->getBaseDirectory();
     $application->addResourceDir($baseDir . DIRECTORY_SEPARATOR . 'Resources');
     $application->addResourceDir(implode(DIRECTORY_SEPARATOR, [$application->getVendorDir(), 'backbee', 'bb-core-js']));
 }