/**
  * Tests the getName() method
  *
  * @return  void
  *
  * @since   3.4
  * @covers  JComponentRouterView::getName
  */
 public function testGetName()
 {
     $this->object->set('name', 'test');
     $this->assertEquals('test', $this->object->getName());
     $this->object->set('name', null);
     $this->assertEquals('jcomponent', $this->object->getName());
 }
Esempio n. 2
0
 /**
  * Build a menu-less URL
  *
  * @param   array  &$query     The vars that should be converted
  * @param   array  &$segments  The URL segments to create
  *
  * @return  void
  *
  * @since   3.4
  */
 public function build(&$query, &$segments)
 {
     $menu_found = false;
     if (isset($query['Itemid'])) {
         $item = $this->router->menu->getItem($query['Itemid']);
         if (!isset($query['option']) || $item && $item->query['option'] == $query['option']) {
             $menu_found = true;
         }
     }
     if (!$menu_found && isset($query['view'])) {
         $views = $this->router->getViews();
         if (isset($views[$query['view']])) {
             $view = $views[$query['view']];
             $segments[] = $query['view'];
             if ($view->key && isset($query[$view->key])) {
                 if (is_callable(array($this->router, 'get' . ucfirst($view->name) . 'Segment'))) {
                     $result = call_user_func_array(array($this->router, 'get' . ucfirst($view->name) . 'Segment'), array($query[$view->key], $query));
                     $segments[] = str_replace(':', '-', array_shift($result));
                 } else {
                     $segments[] = str_replace(':', '-', $query[$view->key]);
                 }
                 unset($query[$views[$query['view']]->key]);
             }
             unset($query['view']);
         }
     }
 }
Esempio n. 3
0
 /**
  * Search Component router constructor
  *
  * @param   JApplicationCms  $app   The application object
  * @param   JMenu            $menu  The menu object to work with
  */
 public function __construct($app = null, $menu = null)
 {
     $params = JComponentHelper::getParams('com_contact');
     $this->noIDs = (bool) $params->get('sef_ids');
     $categories = new JComponentRouterViewconfiguration('categories');
     $categories->setKey('id');
     $this->registerView($categories);
     $category = new JComponentRouterViewconfiguration('category');
     $category->setKey('id')->setParent($categories, 'catid')->setNestable();
     $this->registerView($category);
     $contact = new JComponentRouterViewconfiguration('contact');
     $contact->setKey('id')->setParent($category, 'catid');
     $this->registerView($contact);
     $this->registerView(new JComponentRouterViewconfiguration('featured'));
     parent::__construct($app, $menu);
     $this->attachRule(new JComponentRouterRulesMenu($this));
     $params = JComponentHelper::getParams('com_content');
     if ($params->get('sef_advanced', 0)) {
         $this->attachRule(new JComponentRouterRulesStandard($this));
         $this->attachRule(new JComponentRouterRulesNomenu($this));
     } else {
         JLoader::register('ContactRouterRulesLegacy', __DIR__ . '/helpers/legacyrouter.php');
         $this->attachRule(new ContactRouterRulesLegacy($this));
     }
 }
Esempio n. 4
0
 /**
  * Users Component router constructor
  *
  * @param   JApplicationCms  $app   The application object
  * @param   JMenu            $menu  The menu object to work with
  */
 public function __construct($app = null, $menu = null)
 {
     $this->registerView(new JComponentRouterViewconfiguration('login'));
     $profile = new JComponentRouterViewconfiguration('profile');
     $profile->addLayout('edit');
     $this->registerView($profile);
     $this->registerView(new JComponentRouterViewconfiguration('registration'));
     $this->registerView(new JComponentRouterViewconfiguration('remind'));
     $this->registerView(new JComponentRouterViewconfiguration('reset'));
     parent::__construct($app, $menu);
     $this->attachRule(new JComponentRouterRulesMenu($this));
     $params = JComponentHelper::getParams('com_content');
     if ($params->get('sef_advanced', 0)) {
         $this->attachRule(new JComponentRouterRulesStandard($this));
         $this->attachRule(new JComponentRouterRulesNomenu($this));
     } else {
         JLoader::register('UsersRouterRulesLegacy', __DIR__ . '/helpers/legacyrouter.php');
         $this->attachRule(new UsersRouterRulesLegacy($this));
     }
 }
Esempio n. 5
0
 /**
  * Build a standard URL
  *
  * @param   array  &$query     The vars that should be converted
  * @param   array  &$segments  The URL segments to create
  *
  * @return  void
  *
  * @since   3.4
  */
 public function build(&$query, &$segments)
 {
     // Get the menu item belonging to the Itemid that has been found
     $item = $this->router->menu->getItem($query['Itemid']);
     if (!isset($query['view'])) {
         return;
     }
     // Get all views for this component
     $views = $this->router->getViews();
     // Return directly when the URL of the Itemid is identical with the URL to build
     if (isset($item->query['view']) && $item->query['view'] == $query['view']) {
         $view = $views[$query['view']];
         if (isset($item->query[$view->key]) && $item->query[$view->key] == (int) $query[$view->key]) {
             unset($query[$view->key]);
             while ($view) {
                 unset($query[$view->parent_key]);
                 $view = $view->parent;
             }
             unset($query['view']);
             if (isset($item->query['layout']) && isset($query['layout']) && $item->query['layout'] == $query['layout']) {
                 unset($query['layout']);
             }
             return;
         }
         if (!$view->key) {
             if (isset($item->query['layout']) && isset($query['layout']) && $item->query['layout'] == $query['layout']) {
                 unset($query['view']);
                 unset($query['layout']);
                 return;
             }
         }
     }
     // Get the path from the view of the current URL and parse it to the menu item
     $path = array_reverse($this->router->getPath($query), true);
     $found = false;
     $found2 = false;
     for ($i = 0, $j = count($path); $i < $j; $i++) {
         reset($path);
         $view = key($path);
         if ($found) {
             $ids = array_shift($path);
             if ($views[$view]->nestable) {
                 foreach (array_reverse($ids, true) as $id => $segment) {
                     if ($found2) {
                         $segments[] = str_replace(':', '-', $segment);
                     } else {
                         if ((int) $item->query[$views[$view]->key] == (int) $id) {
                             $found2 = true;
                         }
                     }
                 }
             } else {
                 if (is_bool($ids)) {
                     $segments[] = $views[$view]->name;
                 } else {
                     $segments[] = str_replace(':', '-', array_shift($ids));
                 }
             }
         } else {
             if ($item->query['view'] != $view) {
                 array_shift($path);
             } else {
                 if (!$views[$view]->nestable) {
                     array_shift($path);
                 } else {
                     $i--;
                     $found2 = false;
                 }
                 $found = true;
             }
         }
         unset($query[$views[$view]->parent_key]);
     }
     if ($found) {
         unset($query['layout']);
         unset($query[$views[$query['view']]->key]);
         unset($query['view']);
     }
 }