public function generateLayout($filename, Site $site = null, $extention = self::EXTENSION)
 {
     try {
         $data = Yaml::parse($filename);
         $uid = $this->getUidGenerator()->generateUid($filename, $data, $site);
         $layout = new Layout($uid);
         $layout->setPicPath($layout->getUid() . '.png');
         if ($site !== null) {
             $layout->setSite($site);
         }
         if (array_key_exists('label', $data) && $data['label'] !== null) {
             $layout->setLabel($data['label']);
         } else {
             $layout->setLabel(basename($filename, '.' . self::EXTENSION));
         }
         if (array_key_exists('template', $data)) {
             $this->computeTemplate($layout, $data['template']);
         }
         if (array_key_exists('columns', $data)) {
             $layout->setData($this->computeColumns($data['columns']));
         } else {
             throw new LayoutYamlException('Layout ' . $layout->getLabel() . ' definition need columns', LayoutYamlException::NO_COLUMN_ERROR);
         }
     } catch (ParseException $e) {
         throw new LayoutYamlException($e->getMessage(), LayoutYamlException::LAYOUT_BUILD_ERROR, $e, $e->getParsedFile(), $e->getParsedLine());
     }
     return $layout;
 }
示例#2
0
 /**
  * @covers ::getLayoutsAction
  */
 public function testGetLayoutsAction()
 {
     // authenticate user , set up permissions
     $user = $this->createAuthUser('super_admin', array('ROLE_API_USER'));
     $aclManager = $this->getBBApp()->getContainer()->get('security.acl_manager');
     $aclManager->insertOrUpdateObjectAce(new ObjectIdentity($this->site->getObjectIdentifier(), get_class($this->site)), new UserSecurityIdentity($user->getGroups()[0]->getId(), 'BackBee\\Security\\Group'), MaskBuilder::MASK_VIEW);
     $aclManager->insertOrUpdateObjectAce(new ObjectIdentity('all', 'BackBee\\Site\\Layout'), new UserSecurityIdentity($user->getGroups()[0]->getId(), 'BackBee\\Security\\Group'), MaskBuilder::MASK_VIEW);
     $response = $this->getController()->getLayoutsAction($this->site->getUid());
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('application/json', $response->headers->get('Content-Type'));
     $content = json_decode($response->getContent(), true);
     $this->assertInternalType('array', $content);
     $this->assertCount(1, $content);
     $this->assertEquals($this->layout->getUid(), $content[0]['uid']);
 }
示例#3
0
 private function createFinalResponse(Layout $layout)
 {
     return $this->createResponse('Can\'t create children of ' . $layout->getLabel() . ' layout', 403);
 }
示例#4
0
 public function removeThumbnail(Layout $layout, BBApplication $app)
 {
     $thumbnailfile = $layout->getPicPath();
     if (empty($thumbnail)) {
         return true;
     }
     File::resolveFilepath($thumbnailfile, null, array('include_path' => $app->getResourceDir()));
     while (true === is_file($thumbnailfile) && true === is_writable($thumbnailfile)) {
         @unlink($thumbnailfile);
         $thumbnailfile = $layout->getPicPath();
         File::resolveFilepath($thumbnailfile, null, array('include_path' => $app->getResourceDir()));
     }
     return true;
 }
示例#5
0
 public function createRootPage()
 {
     $page = new Page('test', array('title' => 'title', 'url' => 'url'));
     $layout = new Layout();
     $page->setLayout($layout->setDataObject($this->getDefaultLayoutZones()));
     return $page;
 }
示例#6
0
文件: Page.php 项目: Bensid/BackBee
 /**
  * Sets the layout for the page.
  * Adds as much ContentSet to the page main ContentSet than defined zones in layout.
  *
  * @param  Layout               $layout
  * @param  AbstractClassContent $toPushInMainZone
  *
  * @return Page
  */
 public function setLayout(Layout $layout, AbstractClassContent $toPushInMainZone = null)
 {
     $this->_layout = $layout;
     $count = count($layout->getZones());
     // Add as much ContentSet to the page main ContentSet than defined zones in layout
     for ($i = $this->getContentSet()->count(); $i < $count; $i++) {
         // Do this case really exists ?
         if (null === ($zone = $layout->getZone($i))) {
             $this->getContentSet()->push(new ContentSet());
             continue;
         }
         // Create a new column
         $contentset = new ContentSet(null, $zone->options);
         if (null !== $toPushInMainZone && true === $zone->mainZone) {
             // Existing content push in the main zone
             $contentset->push($toPushInMainZone->setMainNode($this));
         } elseif ('inherited' === $zone->defaultClassContent) {
             // Inherited zone => same ContentSet than parent if exist
             $contentset = $this->getInheritedContent($i, $contentset);
         } elseif ($zone->defaultClassContent) {
             // New default content push
             $contentset->push($this->createNewDefaultContent('BackBee\\ClassContent\\' . $zone->defaultClassContent, $zone->mainZone));
         }
         $this->getContentSet()->push($contentset);
     }
     return $this;
 }
示例#7
0
 /**
  * @covers BackBee\NestedNode\Page::getParentZoneAtSamePositionIfExists
  */
 public function testGetParentZoneAtSamePositionIfExists()
 {
     $page = new Page('test', array('title' => 'title', 'url' => 'url'));
     $page->setLayout(self::$kernel->createLayout('test'));
     $this->assertFalse($this->page->getParentZoneAtSamePositionIfExists($page->getContentSet()->first()));
     $this->assertFalse($this->page->getParentZoneAtSamePositionIfExists($page->getContentSet()->last()));
     $child = new Page('child', array('title' => 'child', 'url' => 'url'));
     $child->setParent($page)->setLayout($page->getLayout());
     $this->assertFalse($child->getParentZoneAtSamePositionIfExists(new ContentSet()));
     $this->assertEquals($page->getContentSet()->first(), $child->getParentZoneAtSamePositionIfExists($child->getContentSet()->first()));
     $this->assertEquals($page->getContentSet()->last(), $child->getParentZoneAtSamePositionIfExists($child->getContentSet()->last()));
     $thirdcolumn = new \stdClass();
     $thirdcolumn->id = 'third';
     $thirdcolumn->defaultContainer = null;
     $thirdcolumn->target = '#target';
     $thirdcolumn->gridClassPrefix = 'row';
     $thirdcolumn->gridSize = 4;
     $thirdcolumn->mainZone = false;
     $thirdcolumn->defaultClassContent = 'inherited';
     $thirdcolumn->options = null;
     $data = self::$kernel->getDefaultLayoutZones();
     $data->templateLayouts[] = $thirdcolumn;
     $layout = new Layout();
     $child->setLayout($layout->setDataObject($data));
     $this->assertEquals($page->getContentSet()->last(), $child->getParentZoneAtSamePositionIfExists($child->getContentSet()->item(1)));
     $this->assertFalse($child->getParentZoneAtSamePositionIfExists($child->getContentSet()->last()));
 }
 public function flush(Layout $layout)
 {
     if (null === $this->app->getEntityManager()->find('BackBee\\Site\\Layout', $layout->getUid())) {
         $this->app->getEntityManager()->persist($layout);
     }
     $this->app->getEntityManager()->flush($layout);
 }
示例#9
0
 /**
  * @covers ::putAction
  */
 public function testPutAction()
 {
     $em = $this->getEntityManager();
     $layout = new Layout();
     $layout->setLabel('Default')->setSite($this->site)->setDataObject(new \stdClass())->setPath($this->getBBApp()->getBaseRepository() . '/Layouts/default.twig');
     $em->persist($layout);
     // create pages
     $homePage = new Page();
     $homePage->setTitle('Page')->setSite($this->site);
     $em->persist($homePage);
     $em->flush();
     $this->getAclManager()->insertOrUpdateObjectAce($homePage, new UserSecurityIdentity($this->group_id, 'BackBee\\Security\\Group'), ['PUBLISH', 'EDIT'])->insertOrUpdateObjectAce($layout, new UserSecurityIdentity($this->group_id, 'BackBee\\Security\\Group'), ['VIEW']);
     $response = $this->sendRequest(self::requestPut('/rest/1/page/' . $homePage->getUid(), ['title' => 'New Page', 'url' => 'url', 'target' => Page::DEFAULT_TARGET, 'state' => Page::STATE_ONLINE, 'layout_uid' => $layout->getUid()]));
     $this->assertEquals(204, $response->getStatusCode());
 }
示例#10
0
文件: phtml.php 项目: gobjila/BackBee
 /**
  * @see BackBee\Renderer\RendererAdapterInterface::updateLayout()
  */
 public function updateLayout(Layout $layout, $layoutFile)
 {
     if (false === $layoutFile) {
         return false;
     }
     $mainLayoutRow = $layout->getDomDocument();
     if (false === $layout->isValid() || null === $mainLayoutRow) {
         throw new RendererException('Malformed data for the layout layout.');
     }
     // Add an php instruction to each final droppable zone found
     $xpath = new \DOMXPath($mainLayoutRow);
     $textNode = $mainLayoutRow->createTextNode('<?php echo $this->container()->first(); ?>');
     $nextNode = $mainLayoutRow->createTextNode('<?php echo $this->container()->next(); ?>');
     foreach ($xpath->query('//div[@class!="clear"]') as $node) {
         if (!$node->hasChildNodes()) {
             $node->appendChild(clone $textNode);
             $textNode = $nextNode;
         }
     }
     libxml_use_internal_errors(true);
     $domlayout = new \DOMDocument();
     $layoutcontent = str_replace(array('<?php', '?>'), array('&lt;?php', '?&gt;'), file_get_contents($layoutFile));
     @$domlayout->loadHTML($layoutcontent);
     $domlayout->formatOutput = true;
     $layoutNode = $domlayout->importNode($mainLayoutRow->firstChild, true);
     $layoutid = $layoutNode->getAttribute('id');
     $xPath = new \DOMXPath($domlayout);
     if (($targetNodes = $xPath->query('//div[@id="' . $layoutid . '"]')) && 0 < $targetNodes->length) {
         foreach ($targetNodes as $targetNode) {
             $targetNode->parentNode->replaceChild($layoutNode, $targetNode);
         }
     } elseif (($targetNodes = $domlayout->getElementsByTagName('body')) && 0 < $targetNodes->length) {
         foreach ($targetNodes as $targetNode) {
             $targetNode->appendChild($layoutNode);
         }
     } else {
         $domlayout->appendChild($layoutNode);
     }
     if (!file_put_contents($layoutFile, preg_replace_callback('/(&lt;|<)\\?php(.+)\\?(&gt;|>)/iu', create_function('$matches', 'return "<?php".html_entity_decode(urldecode($matches[2]))."?".">";'), $domlayout->saveHTML()))) {
         throw new RendererException(sprintf('Unable to save layout %s.', $layoutFile), RendererException::LAYOUT_ERROR);
     }
     libxml_clear_errors();
     return $layoutFile;
 }
 /**
  * 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;
 }
示例#12
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;
 }
示例#13
0
 public function createLayout($label, $uid = null)
 {
     $layout = new Layout($uid);
     $layout->setLabel($label);
     $layout->setPath('/' . $label);
     $layout->setDataObject($this->getDefaultLayoutZones());
     return $layout;
 }