Exemplo n.º 1
0
 public function testConstructDefault()
 {
     $item = new Item('foobar', 'foobar/');
     $this->assertTrue($item instanceof Item);
     $this->assertEquals('Foobar', $item->getText());
     $this->assertEquals('foobar/', $item->getHref());
 }
Exemplo n.º 2
0
 /**
  * Get the root path
  *
  * @return string
  */
 protected function getRootPath()
 {
     // If there is no root item, the root is the content dir
     if (null === $this->_rootItem) {
         return $this->_contentDir;
     }
     return $this->_contentDir . DIRECTORY_SEPARATOR . $this->_rootItem->getRawHref();
 }
Exemplo n.º 3
0
 /**
  * Get URL for this content
  *
  * @return void
  */
 public function getUrl()
 {
     $path = $this->getFile();
     $name = $this->getName();
     // The base URL tells us the web root of the application
     $baseUrl = $this->getTheme()->getAssetManager()->getBaseUrl();
     // The content dir gives the full path to the directory of this
     // collection.
     $contentDir = $this->getView()->getContentDir();
     // Strip off the content dir from the full path so we're left with the
     // relative web root of the file
     $webPath = dirname(str_replace($contentDir . DIRECTORY_SEPARATOR, '', $path));
     $webPath = NavItem::translateOrderedName($webPath);
     // The url is the baseUrl + '/' + webPath + '/' + name of object
     $url = rtrim($baseUrl, '/') . '/' . $webPath . '/' . $name;
     return $url;
 }
Exemplo n.º 4
0
 /**
  * Create map of available folders and files in the content directory
  *
  * @return array
  */
 public function createMap()
 {
     $files = self::rglob($this->getContentDir() . DIRECTORY_SEPARATOR . '*');
     $map = array();
     foreach ($files as $file) {
         if (is_dir($file)) {
             $isDir = true;
         } else {
             $isDir = false;
         }
         // Remove the common first part
         $file = str_replace($this->getContentDir() . '/', '', $file);
         $url = str_replace('.md', '', $file);
         $url = NavigationItem::translateOrderedName($url);
         if ($url == 'index') {
             // If we're left with just index, change to home page
             $map['/'] = $file;
             continue;
         }
         if ($isDir) {
             $map[$url . '/'] = $file;
             $map[$url] = array('canonical' => $url . '/');
             continue;
         }
         // If the last segment is 'index', add an entry for the
         // file without the word 'index'
         $urlSegments = explode('/', $url);
         if (end($urlSegments) == 'index') {
             $url = str_replace('index', '', $url);
             $map[$url] = $file;
             $map[rtrim($url, '/')] = array('canonical' => $url);
             continue;
         }
         $map[$url] = $file;
     }
     return $map;
 }