1 <?php
 2 /**
 3  * @package     Joomla.Libraries
 4  * @subpackage  Pathway
 5  *
 6  * @copyright   Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
 7  * @license     GNU General Public License version 2 or later; see LICENSE.txt
 8  */
 9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Class to manage the site application pathway.
14  *
15  * @since  1.5
16  */
17 class JPathwaySite extends JPathway
18 {
19     /**
20      * Class constructor.
21      *
22      * @param   array  $options  The class options.
23      *
24      * @since   1.5
25      */
26     public function __construct($options = array())
27     {
28         $this->_pathway = array();
29 
30         $app  = JApplicationCms::getInstance('site');
31         $menu = $app->getMenu();
32         $lang = JFactory::getLanguage();
33 
34         if ($item = $menu->getActive())
35         {
36             $menus = $menu->getMenu();
37 
38             // Look for the home menu
39             if (JLanguageMultilang::isEnabled())
40             {
41                 $home = $menu->getDefault($lang->getTag());
42             }
43             else
44             {
45                 $home  = $menu->getDefault();
46             }
47 
48             if (is_object($home) && ($item->id != $home->id))
49             {
50                 foreach ($item->tree as $menupath)
51                 {
52                     $link = $menu->getItem($menupath);
53 
54                     switch ($link->type)
55                     {
56                         case 'separator':
57                         case 'heading':
58                             $url = null;
59                             break;
60 
61                         case 'url':
62                             if ((strpos($link->link, 'index.php?') === 0) && (strpos($link->link, 'Itemid=') === false))
63                             {
64                                 // If this is an internal Joomla link, ensure the Itemid is set.
65                                 $url = $link->link . '&Itemid=' . $link->id;
66                             }
67                             else
68                             {
69                                 $url = $link->link;
70                             }
71                             break;
72 
73                         case 'alias':
74                             // If this is an alias use the item id stored in the parameters to make the link.
75                             $url = 'index.php?Itemid=' . $link->params->get('aliasoptions');
76                             break;
77 
78                         default:
79                             $url = $link->link . '&Itemid=' . $link->id;
80                             break;
81                     }
82 
83                     $this->addItem($menus[$menupath]->title, $url);
84                 }
85             }
86         }
87     }
88 }
89