Пример #1
0
 /**
  * Returns the page path
  *
  * This method will return the requested url.
  */
 public function getPagePath()
 {
     $core = $this->getLoops()->getService("web_core");
     $page = $core->page;
     $pagepath = $page === $this ? "" : WebCore::getPagePathFromClassname($page, $core->page_parameter);
     return implode("/", $pagepath ? array_merge([$pagepath], $core->parameter) : $core->parameter);
 }
Пример #2
0
 public function __construct(ElementInterface $context, $page_parameter = NULL, Loops $loops = NULL)
 {
     parent::__construct($context, $loops);
     $loops = $this->getLoops();
     $annotations = $loops->getService("annotations");
     if ($page_parameter === NULL) {
         $page_parameter = $loops->getService("web_core")->page_parameter;
     }
     $reflection = new ReflectionClass(get_class($context));
     $entries = [];
     do {
         $classname = $reflection->getName();
         $annotation_set = $annotations->getStrict($classname);
         $annotation = $annotation_set->findFirst("Navigation\\PageEntry");
         $breadcrumb_annotation = $annotation_set->findFirst("Navigation\\Breadcrumb");
         $annotation_title = $annotation_set->findFirst("Navigation\\Title");
         if ($breadcrumb_annotation && $breadcrumb_annotation->ignore) {
             continue;
         }
         if ($breadcrumb_annotation && $breadcrumb_annotation->title) {
             $title = $breadcrumb_annotation->title;
         } elseif ($annotation && $annotation->title) {
             $title = $annotation->title;
         } elseif ($annotation_title && $annotation_title->title) {
             $title = $annotation_title->title;
         } else {
             continue;
         }
         $entry = new PageEntry(substr($classname, 6), $page_parameter, $title, $loops);
         if ($annotation && $annotation->link) {
             $entry->link = WebCore::getPagePathFromClassname("Pages\\" . $annotation->link, $page_parameter);
         }
         $entries[] = $entry;
     } while ($reflection = $reflection->getParentClass());
     foreach (array_reverse($entries) as $key => $entry) {
         $this->addChild($key, $entry);
     }
 }
Пример #3
0
 /**
  * @param string|object $page The page where this navigation entry points to
  * @param string|object $highlightgroup If the page inherits from this class/object, the entry will be highlighted. Defaults to $page if not specified.
  * @param string $title The title for this entry. Defaults to classname of page if not found in annotations.
  */
 public function __construct($page, $page_parameter = NULL, $title = "", Loops $loops = NULL)
 {
     $prefix = "Pages\\";
     if (!$loops) {
         $loops = Loops::getLoops();
     }
     $core = $loops->getService("web_core");
     $this->pageclass = $pageclass = is_object($page) ? get_class($page) : $prefix . $page;
     if (!class_exists($pageclass)) {
         throw new Exception("Class '{$pageclass}' does not exist.");
     }
     $count = WebCore::getParameterCount($pageclass);
     if ($page_parameter === NULL) {
         $page_parameter = array_slice($core->page_parameter, 0, $count);
     }
     if (!$title) {
         if ($annotation = $loops->getService("annotations")->get($this->pageclass)->findFirst("Navigation\\Title")) {
             $title = $annotation->title;
         }
     }
     if (!$title) {
         if (is_object($page)) {
             $title = get_class($page);
             if (substr($title, 0, strlen($prefix)) == $prefix) {
                 $title = substr($title, strlen($prefix));
             }
         } else {
             $title = $page;
         }
     }
     $link = WebCore::getPagePathFromClassname($pageclass, $page_parameter);
     parent::__construct($link, $title, $loops);
     $this->highlight = is_a($core->page, $pageclass, TRUE) && implode("/", array_slice($core->page_parameter, 0, $count)) == implode("/", array_slice($page_parameter, 0, $count));
 }
Пример #4
0
 public static function createSiteMap($filter = NULL, $designated_parameter = [], $object_filter = NULL, Loops $loops = NULL)
 {
     if (!$loops) {
         $loops = Loops::getCurrentLoops();
     }
     $annotations = $loops->getService("annotations");
     $classnames = $loops->getService("application")->definedClasses();
     if ($object_filter) {
         if (is_object($object_filter)) {
             $object_filter = get_class($object_filter);
         }
         if (is_string($object_filter)) {
             $classnames = array_filter($classnames, function ($classname) use($object_filter) {
                 return is_a($classname, $object_filter, TRUE);
             });
         }
     }
     $entries = [];
     foreach ($classnames as $classname) {
         if (!($annotation = $annotations->getStrict($classname)->findFirst("Navigation\\PageEntry"))) {
             continue;
         }
         if ($filter != $annotation->filter) {
             continue;
         }
         $highlight = $annotation->highlight ? "Pages\\" . $annotation->highlight : NULL;
         $link = WebCore::getPagePathFromClassname($annotation->link ? "Pages\\" . $annotation->link : $classname, $designated_parameter);
         if ($link !== FALSE) {
             $entry = new PageEntry(substr($classname, 6), $designated_parameter, $annotation->title, $loops);
             if ($annotation->link) {
                 $entry->link = WebCore::getPagePathFromClassname("Pages\\" . $annotation->link, $designated_parameter);
             }
             $entries[] = [$classname, $annotation, $entry];
         }
     }
     if ($entries) {
         usort($entries, function ($a, $b) {
             if ($result = count(class_parents($a[0])) - count(class_parents($b[0]))) {
                 return $result;
             }
             if ($result = $a[1]->order - $b[1]->order) {
                 return $result;
             }
             if ($result = strcmp($a[1]->name, $b[1]->name)) {
                 return $result;
             }
             if ($result = strcmp($a[1]->title, $b[1]->title)) {
                 return $result;
             }
             if ($result = strcmp($a[0], $b[0])) {
                 return $result;
             }
             return 0;
         });
         self::groupEntries($entries, $loops);
     }
     $result = [];
     foreach ($entries as $key => $entry) {
         $result[$entry[1]->name ?: $key] = $entry[2];
     }
     return $result;
 }
Пример #5
0
 /**
  * Returns the page path of this page
  *
  * The result is retrieved from the WebCore, if the page was created with parameters they will
  * be taken into account when creating the page path. I.e. underscore namespaces will be replaced
  * by the parameters.
  *
  * Note: If the page is not defined inside the Pages namespace, WebCore::getPagePathFromClassname will
  * return FALSE.
  *
  * Currently page path resolving will only work if an application service is defined. This may be fixed
  * in the future.
  *
  * @return string|FALSE The page path or FALSE if the page is invalid.
  */
 public function getPagePath()
 {
     return WebCore::getPagePathFromClassname(get_class($this), $this->parameter, $this->getLoops());
 }