PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/application/pathway.php

https://github.com/joebushi/joomla
PHP | 206 lines | 81 code | 27 blank | 98 comment | 5 complexity | 727dbeab1c73fc50e738c5f085ff7daf MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Framework
  5. * @subpackage Application
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. // No direct access
  10. defined('JPATH_BASE') or die;
  11. /**
  12. * Class to maintain a pathway.
  13. *
  14. * Main example of use so far is the mod_breadcrumbs module that keeps track of
  15. * the user's navigated path within the Joomla application.
  16. *
  17. * @abstract
  18. * @package Joomla.Framework
  19. * @subpackage Application
  20. * @since 1.5
  21. */
  22. class JPathway extends JObject
  23. {
  24. /**
  25. * Array to hold the pathway item objects
  26. * @access private
  27. */
  28. var $_pathway = null;
  29. /**
  30. * Integer number of items in the pathway
  31. * @access private
  32. */
  33. var $_count = 0;
  34. /**
  35. * Class constructor
  36. */
  37. function __construct($options = array())
  38. {
  39. //Initialise the array
  40. $this->_pathway = array();
  41. }
  42. /**
  43. * Returns a JPathway object
  44. *
  45. * @access public
  46. * @param string $client The name of the client
  47. * @param array $options An associative array of options
  48. * @return JPathway A pathway object.
  49. * @since 1.5
  50. */
  51. static function getInstance($client, $options = array())
  52. {
  53. static $instances;
  54. if (!isset($instances)) {
  55. $instances = array();
  56. }
  57. if (empty($instances[$client]))
  58. {
  59. //Load the router object
  60. $info = &JApplicationHelper::getClientInfo($client, true);
  61. $path = $info->path.DS.'includes'.DS.'pathway.php';
  62. if (file_exists($path))
  63. {
  64. require_once $path;
  65. // Create a JPathway object
  66. $classname = 'JPathway'.ucfirst($client);
  67. $instance = new $classname($options);
  68. }
  69. else
  70. {
  71. $error = JError::raiseError(500, 'Unable to load pathway: '.$client);
  72. return $error;
  73. }
  74. $instances[$client] = & $instance;
  75. }
  76. return $instances[$client];
  77. }
  78. /**
  79. * Return the JPathWay items array
  80. *
  81. * @access public
  82. * @return array Array of pathway items
  83. * @since 1.5
  84. */
  85. function getPathway()
  86. {
  87. $pw = $this->_pathway;
  88. // Use array_values to reset the array keys numerically
  89. return array_values($pw);
  90. }
  91. /**
  92. * Set the JPathway items array.
  93. *
  94. * @access public
  95. * @param array $pathway An array of pathway objects.
  96. * @return array The previous pathway data.
  97. * @since 1.5
  98. */
  99. function setPathway($pathway)
  100. {
  101. $oldPathway = $this->_pathway;
  102. $pathway = (array) $pathway;
  103. // Set the new pathway.
  104. $this->_pathway = array_values($pathway);
  105. return array_values($oldPathway);
  106. }
  107. /**
  108. * Create and return an array of the pathway names.
  109. *
  110. * @access public
  111. * @return array Array of names of pathway items
  112. * @since 1.5
  113. */
  114. function getPathwayNames()
  115. {
  116. // Initialise variables.
  117. $names = array (null);
  118. // Build the names array using just the names of each pathway item
  119. foreach ($this->_pathway as $item) {
  120. $names[] = $item->name;
  121. }
  122. //Use array_values to reset the array keys numerically
  123. return array_values($names);
  124. }
  125. /**
  126. * Create and add an item to the pathway.
  127. *
  128. * @access public
  129. * @param string $name
  130. * @param string $link
  131. * @return boolean True on success
  132. * @since 1.5
  133. */
  134. function addItem($name, $link='')
  135. {
  136. // Initalize variables
  137. $ret = false;
  138. if ($this->_pathway[] = $this->_makeItem($name, $link)) {
  139. $ret = true;
  140. $this->_count++;
  141. }
  142. return $ret;
  143. }
  144. /**
  145. * Set item name.
  146. *
  147. * @access public
  148. * @param integer $id
  149. * @param string $name
  150. * @return boolean True on success
  151. * @since 1.5
  152. */
  153. function setItemName($id, $name)
  154. {
  155. // Initalize variables
  156. $ret = false;
  157. if (isset($this->_pathway[$id])) {
  158. $this->_pathway[$id]->name = $name;
  159. $ret = true;
  160. }
  161. return $ret;
  162. }
  163. /**
  164. * Create and return a new pathway object.
  165. *
  166. * @access private
  167. * @param string $name Name of the item
  168. * @param string $link Link to the item
  169. * @return object Pathway item object
  170. * @since 1.5
  171. */
  172. function _makeItem($name, $link)
  173. {
  174. $item = new stdClass();
  175. $item->name = html_entity_decode($name);
  176. $item->link = $link;
  177. return $item;
  178. }
  179. }