Example #1
0
 /**
  * Invokes the dispatcher
  */
 public function run()
 {
     $argumentsString = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
     $arguments = array();
     if ($argumentsString) {
         parse_str($argumentsString, $tempArguments);
         foreach ($tempArguments as $argumentKey => $argumentValue) {
             $argumentKey = filter_var($argumentKey, FILTER_SANITIZE_STRING);
             $argumentValue = filter_var($argumentValue, FILTER_SANITIZE_STRING);
             $arguments[$argumentKey] = $argumentValue;
         }
     }
     $uri = '';
     if (isset($_SERVER['PATH_INFO'])) {
         $uri = $_SERVER['PATH_INFO'];
     } else {
         if (isset($_SERVER['REQUEST_URI'])) {
             $uriParts = explode('?', $_SERVER['REQUEST_URI'], 2);
             $uri = $uriParts[0];
         } else {
             if (isset($_GET['u'])) {
                 $uri = $_GET['u'];
             }
         }
     }
     $uri = str_replace(' ', Page::URI_WHITESPACE_REPLACE, $uri);
     $uri = filter_var($uri, FILTER_SANITIZE_URL);
     $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
     Dispatcher::getSharedDispatcher()->dispatch($uri, $method, $arguments);
 }
Example #2
0
File: Menu.php Project: cundd/noshi
 /**
  * @param array $pages
  * @return string
  */
 public function renderPages($pages)
 {
     $output = '<ul>';
     $currentPage = Dispatcher::getSharedDispatcher()->getPage();
     foreach ($pages as $pageData) {
         $uri = '#';
         $title = '';
         $target = '';
         $class = '';
         if (isset($pageData['page']) && $pageData['page']) {
             // Page object
             /** @var Page $page */
             $page = $pageData['page'];
             $uri = $page->getUri();
             $title = $page->getTitle();
             $target = $page->getIsExternalLink() ? '_blank' : '';
             if ($currentPage) {
                 if ($page === $currentPage || $page->getIdentifier() === $currentPage->getIdentifier()) {
                     $class = 'active';
                 }
             }
         } else {
             // Directory array
             $title = $pageData['title'];
         }
         $output .= '<li' . ($class ? ' class="' . $class . '"' : '') . '>';
         $output .= '<a href="' . $uri . '"';
         if ($target) {
             $output .= ' target="' . $target . '"';
         }
         $output .= '>' . $title . '</a>';
         if (isset($pageData['children']) && $pageData['children']) {
             $output .= $this->renderPages($pageData['children']);
         }
         $output .= '</li>';
     }
     $output .= '</ul>';
     return $output;
 }