Beispiel #1
0
 /**
  * Class constructor.
  *
  * @param array                    $options Initial options for the cache adapter:
  *                                          - cachedir string The cache directory
  * @param string                   $context An optional cache context
  * @param \Psr\Log\LoggerInterface $logger  An optional logger
  *
  * @throws \BackBee\Cache\Exception\CacheException Occurs if the cache directory doesn't exist, can not
  *                                                 be created or is not writable.
  */
 public function __construct(array $options = array(), $context = null, LoggerInterface $logger = null)
 {
     parent::__construct($options, $context, $logger);
     $this->cachedir = $this->_instance_options['cachedir'];
     if (null !== $this->getContext()) {
         $this->cachedir .= DIRECTORY_SEPARATOR . StringUtils::toPath($this->getContext());
     }
     if (true === $this->_instance_options['cacheautogenerate'] && false === is_dir($this->cachedir) && false === @mkdir($this->cachedir, 0755, true)) {
         throw new CacheException(sprintf('Unable to create the cache directory `%s`.', $this->cachedir));
     }
     if (true === $this->_instance_options['cacheautogenerate'] && false === is_writable($this->cachedir)) {
         throw new CacheException(sprintf('Unable to write in the cache directory `%s`.', $this->cachedir));
     }
     $this->log('info', sprintf('File cache system initialized with directory set to `%s`.', $this->cachedir));
 }
    server_name <?php 
    echo $site['domain'];
    ?>
;
    root <?php 
    echo __DIR__ . '/';
    ?>
;

    error_log /var/log/nginx/<?php 
    echo \BackBee\Utils\StringUtils::urlize($site['label']);
    ?>
.error.log;
    access_log /var/log/nginx/<?php 
    echo \BackBee\Utils\StringUtils::urlize($site['label']);
    ?>
.access.log;

    location ~ /resources/(.*) {
        alias <?php 
    echo dirname(__DIR__) . '/';
    ?>
;
        try_files /repository/Resources/$1 /vendor/backbee/backbee/Resources/$1 @rewriteapp;
    }

    location @emptygif404 { empty_gif; }

    location / {
        try_files $uri @rewriteapp;
Beispiel #3
0
 /**
  * Computes the URL of a page according to a scheme.
  *
  * @param array         $scheme  The scheme to apply
  * @param Page          $page    The page
  * @param  AbstractClassContent $content The optionnal main content of the page
  * @return string        The generated URL
  */
 private function doGenerate($scheme, Page $page, AbstractClassContent $content = null)
 {
     $replacement = ['$parent' => $page->isRoot() ? '' : $page->getParent()->getUrl(false), '$title' => StringUtils::urlize($page->getTitle()), '$datetime' => $page->getCreated()->format('ymdHis'), '$date' => $page->getCreated()->format('ymd'), '$time' => $page->getCreated()->format('His')];
     $matches = [];
     if (preg_match_all('/(\\$content->[a-z]+)/i', $scheme, $matches)) {
         foreach ($matches[1] as $pattern) {
             $property = explode('->', $pattern);
             $property = array_pop($property);
             try {
                 $replacement[$pattern] = StringUtils::urlize($content->{$property});
             } catch (\Exception $e) {
                 $replacement[$pattern] = '';
             }
         }
     }
     $matches = [];
     if (preg_match_all('/(\\$ancestor\\[([0-9]+)\\])/i', $scheme, $matches)) {
         foreach ($matches[2] as $level) {
             $ancestor = $this->application->getEntityManager()->getRepository('BackBee\\CoreDomain\\NestedNode\\Page')->getAncestor($page, $level);
             if (null !== $ancestor && $page->getLevel() > $level) {
                 $replacement['$ancestor[' . $level . ']'] = $ancestor->getUrl(false);
             } else {
                 $replacement['$ancestor[' . $level . ']'] = '';
             }
         }
     }
     $url = preg_replace('/\\/+/', '/', str_replace(array_keys($replacement), array_values($replacement), $scheme));
     return $this->getUniqueness($page, $url);
 }
 /**
  * Create a media folder
  * and if a parent is provided added has its last child
  *
  * @param MediaFolder $mediaFolder
  *
  * @Rest\RequestParam(name="title", description="media title", requirements={
  *   @Assert\NotBlank()
  * })
  * @ParamConverter(
  *   name="parent", id_name="parent_uid", id_source="request", class="BackBee\NestedNode\MediaFolder", required=false
  * )
  * @Rest\Security("is_fully_authenticated() & has_role('ROLE_API_USER') & is_granted('CREATE', '\BackBee\NestedNode\MediaFolder')")
  */
 public function postAction(Request $request, $parent = null)
 {
     try {
         $title = trim($request->request->get('title'));
         $uid = $request->request->get('uid', null);
         if (null !== $uid) {
             $mediaFolder = $this->getMediaFolderRepository()->find($uid);
             $mediaFolder->setTitle($title);
         } else {
             $mediaFolder = new MediaFolder();
             $mediaFolder->setUrl($request->request->get('url', StringUtils::urlize($title)));
             $mediaFolder->setTitle($title);
             if (null === $parent) {
                 $parent = $this->getMediaFolderRepository()->getRoot();
             }
             if ($this->mediaFolderAlreadyExists($title, $parent)) {
                 throw new BadRequestHttpException(sprintf('A MediaFolder named `%s` already exists in `%s`.', $title, $parent->getTitle()));
             }
             $mediaFolder->setParent($parent);
             $this->getMediaFolderRepository()->insertNodeAsLastChildOf($mediaFolder, $parent);
         }
         $this->getEntityManager()->persist($mediaFolder);
         $this->getEntityManager()->flush();
         $response = $this->createJsonResponse(null, 201, ['BB-RESOURCE-UID' => $mediaFolder->getUid(), 'Location' => $this->getApplication()->getRouting()->getUrlByRouteName('bb.rest.media-folder.get', ['version' => $request->attributes->get('version'), 'uid' => $mediaFolder->getUid()], '', false)]);
     } catch (\Exception $e) {
         $response = $this->createResponse(sprintf('Internal server error: %s', $e->getMessage()));
     }
     return $response;
 }
 /**
  * Create new site entry inside sites.yml file
  *
  * @return CreateWebsiteCommand
  */
 protected function runSitesYmlProcess()
 {
     $sitesConf = $this->bbapp->getConfig()->getSitesConfig();
     if ($this->siteDomain === null) {
         throw new \InvalidArgumentException('This site domain is not valid (empty value)');
     }
     if (is_array($sitesConf) && array_key_exists($this->siteLabel, $sitesConf)) {
         throw new \InvalidArgumentException('This label `' . $this->siteLabel . '` already present in sites.yml');
     }
     $newSite = [\BackBee\Utils\StringUtils::urlize($this->siteLabel) => ['label' => $this->siteLabel, 'domain' => $this->siteDomain]];
     $newSitesConf = is_array($sitesConf) ? array_merge($sitesConf, $newSite) : $newSite;
     file_put_contents($this->bbapp->getBaseDir() . DIRECTORY_SEPARATOR . 'repository/Config/sites.yml', Yaml::dump($newSitesConf));
     return $this;
 }
 /**
  * Return a cleaned string.
  *
  * @param string $str
  *
  * @return string
  */
 protected function _cleanText($str)
 {
     return trim(html_entity_decode(html_entity_decode(String::toUTF8($str), ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8'));
 }
 /**
  * Bulk permissions create/update.
  *
  *
  * @Rest\Security("is_fully_authenticated() & has_role('ROLE_API_USER')")
  */
 public function postPermissionMapAction(Request $request)
 {
     $permissionMap = $request->request->all();
     $aclManager = $this->getContainer()->get("security.acl_manager");
     $violations = new ConstraintViolationList();
     foreach ($permissionMap as $i => $objectMap) {
         $permissions = $objectMap['permissions'];
         if (!isset($objectMap['object_class'])) {
             $violations->add(new ConstraintViolation("Object class not supllied", "Object class not supllied", [], sprintf('%s[object_class]', $i), sprintf('%s[object_class]', $i), null));
             continue;
         }
         $objectClass = $objectMap['object_class'];
         $objectId = null;
         if (!class_exists($objectClass)) {
             $violations->add(new ConstraintViolation("Class {$objectClass} doesn't exist", "Class {$objectClass} doesn't exist", [], sprintf('%s[object_class]', $i), sprintf('%s[object_class]', $i), $objectClass));
             continue;
         }
         $objectIdentity = null;
         if (isset($objectMap['object_id'])) {
             $objectId = $objectMap['object_id'];
             // object scope
             $objectIdentity = new ObjectIdentity($objectId, $objectClass);
         } else {
             // class scope
             $objectIdentity = new ObjectIdentity('class', $objectClass);
         }
         if (!isset($objectMap['sid'])) {
             $violations->add(new ConstraintViolation("Security ID not supllied", "Security ID not supllied", [], sprintf('%s[sid]', $i), sprintf('%s[sid]', $i), null));
             continue;
         }
         $sid = $objectMap['sid'];
         $securityIdentity = new UserSecurityIdentity($sid, 'BackBee\\Security\\Group');
         // convert values to booleans
         $permissions = array_map(function ($val) {
             return \BackBee\Utils\StringUtils::toBoolean((string) $val);
         }, $permissions);
         // remove false values
         $permissions = array_filter($permissions);
         $permissions = array_keys($permissions);
         $permissions = array_unique($permissions);
         try {
             $mask = $aclManager->getMask($permissions);
         } catch (\BackBee\Security\Acl\Permission\InvalidPermissionException $e) {
             $violations->add(new ConstraintViolation($e->getMessage(), $e->getMessage(), [], sprintf('%s[permissions]', $i), sprintf('%s[permissions]', $i), $e->getPermission()));
             continue;
         }
         if ($objectId) {
             $aclManager->insertOrUpdateObjectAce($objectIdentity, $securityIdentity, $mask);
         } else {
             $aclManager->insertOrUpdateClassAce($objectIdentity, $securityIdentity, $mask);
         }
     }
     if (count($violations) > 0) {
         throw new ValidationException($violations);
     }
     return new Response('', 204);
 }
 /**
  * Return the file path to current layout, try to create it if not exists.
  *
  * @param Layout $layout
  *
  * @return string the file path
  *
  * @throws RendererException
  */
 protected function getLayoutFile(Layout $layout)
 {
     $layoutfile = $layout->getPath();
     if (null === $layoutfile && 0 < count($this->_includeExtensions)) {
         $ext = reset($this->_includeExtensions);
         $layoutfile = StringUtils::toPath($layout->getLabel(), array('extension' => $ext));
         $layout->setPath($layoutfile);
     }
     return $layoutfile;
 }
Beispiel #9
0
 /**
  * Return the file path to current layout, try to create it if not exists.
  *
  * @param Layout $layout
  *
  * @return string the file path
  *
  * @throws RendererException
  */
 protected function getLayoutFile(Layout $layout)
 {
     $layoutfile = $layout->getPath();
     if (null === $layoutfile && 0 < $this->manageableExt->count()) {
         $adapter = null;
         if (null !== $this->defaultAdapter && null !== ($adapter = $this->rendererAdapters->get($this->defaultAdapter))) {
             $extensions = $adapter->getManagedFileExtensions();
         } else {
             $extensions = $this->manageableExt->keys();
         }
         if (0 === count($extensions)) {
             throw new RendererException('Declared adapter(s) (count:' . $this->rendererAdapters->count() . ') is/are not able to manage ' . 'any file extensions at moment.');
         }
         $layoutfile = StringUtils::toPath($layout->getLabel(), array('extension' => reset($extensions)));
         $layout->setPath($layoutfile);
     }
     return $layoutfile;
 }
 public function testFormatBytes()
 {
     $this->assertEquals('1.953 kb', StringUtils::formatBytes(2000, 3));
     $this->assertEquals('553.71094 kb', StringUtils::formatBytes(567000, 5));
     $this->assertEquals('553.71 kb', StringUtils::formatBytes(567000));
     $this->assertEquals('5.28 gb', StringUtils::formatBytes(5670008902));
 }