Ejemplo n.º 1
0
 /**
  * Returns all available pages for the given path
  *
  * @param string $path
  * @param string $uriBase
  * @return array
  */
 public function getPagesForPath($path, $uriBase = '')
 {
     $pages = array();
     $pagesSortingMap = array();
     $pagesIdentifierMap = array();
     if ($handle = opendir($path)) {
         $dataSuffix = '.' . ConfigurationManager::getConfiguration()->get('dataSuffix');
         $dataSuffixLength = strlen($dataSuffix);
         while (FALSE !== ($file = readdir($handle))) {
             // Skip the current file if the first character is a dot
             if ($file[0] === '.') {
                 continue;
             }
             // Skip hidden pages
             if ($file[0] === '_') {
                 continue;
             }
             $isFolder = strpos($file, '.') === FALSE;
             $isPage = substr($file, -$dataSuffixLength) === $dataSuffix;
             $isConfig = substr($file, -5) === '.json';
             if (!($isFolder || $isPage || $isConfig)) {
                 continue;
             }
             $relativePageIdentifier = str_replace(' ', Page::URI_WHITESPACE_REPLACE, substr($file, 0, strrpos($file, '.')));
             $pageIdentifier = ($uriBase ? $uriBase . '/' : '') . ($relativePageIdentifier ? $relativePageIdentifier : $file);
             /** @var Page $page */
             $page = $this->findByIdentifier($pageIdentifier);
             $page->setIsDirectory($isFolder);
             $sorting = $page->getSorting();
             $sortingDescriptor = sprintf('%05d-%s', $sorting, $pageIdentifier);
             /*
              * Build the page data merged with previous definitions
              * Page definition is more important than the Directory definition
              */
             $pageData = array_merge(isset($pagesIdentifierMap[$pageIdentifier]) ? $pagesIdentifierMap[$pageIdentifier] : array(), array('id' => $pageIdentifier, 'page' => $page, 'sorting' => $sorting, 'sorting_descriptor' => $sortingDescriptor));
             /*
              * If the current page is a folder get the children
              */
             if ($isFolder) {
                 $pageData['children'] = $this->getPagesForPath($path . $file . DIRECTORY_SEPARATOR, $pageIdentifier);
             }
             $pagesSortingMap[$sortingDescriptor] = $pageData;
             $pagesIdentifierMap[$pageIdentifier] = $pageData;
         }
         closedir($handle);
     }
     // Add the page to the list pages
     ksort($pagesSortingMap, SORT_NUMERIC);
     $tempPages = array();
     foreach ($pagesSortingMap as $pageWithSorting) {
         $tempPages[$pageWithSorting['id']] = $pageWithSorting['page'];
     }
     $this->allPages = array_merge($this->allPages, $tempPages);
     ksort($pages, SORT_NUMERIC);
     return $pagesSortingMap;
 }
Ejemplo n.º 2
0
 /**
  * Returns the alias for the given URI, or the original URI if no alias is defined
  *
  * At the current stage this method doesn't do much. It simply returns "/Home/" if the current URI is "/"
  *
  * @param string $uri
  * @return string
  */
 public function getAliasForUri($uri)
 {
     $routingConfiguration = ConfigurationManager::getConfiguration()->get('routing');
     $aliasConfiguration = isset($routingConfiguration['alias']) ? $routingConfiguration['alias'] : array();
     return isset($aliasConfiguration[$uri]) ? $aliasConfiguration[$uri] : $uri;
 }
Ejemplo n.º 3
0
 /**
  * Render the UI element
  *
  * @return string
  */
 public function render()
 {
     $resourcePath = ConfigurationManager::getConfiguration()->getResourceDirectoryUri();
     $fileSuffix = intval(@date('H')) > 18 ? '-dark' : '';
     return "<link rel=\"stylesheet\" href=\"{$resourcePath}/Stylesheets/main{$fileSuffix}.css\" />";
 }