PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_content/helpers/route.php

https://github.com/joebushi/joomla
PHP | 139 lines | 101 code | 16 blank | 22 comment | 17 complexity | 4bac60f177fd0ab61fbf9d38272fc54c MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla
  5. * @subpackage com_content
  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('_JEXEC') or die;
  11. // Component Helper
  12. jimport('joomla.application.component.helper');
  13. jimport('joomla.application.categorytree');
  14. /**
  15. * Content Component Route Helper
  16. *
  17. * @static
  18. * @package Joomla
  19. * @subpackage com_content
  20. * @since 1.5
  21. */
  22. abstract class ContentHelperRoute
  23. {
  24. /**
  25. * @param int The route of the content item
  26. */
  27. public static function getArticleRoute($id, $catid)
  28. {
  29. if ($catid)
  30. {
  31. jimport('joomla.application.categories');
  32. $categoryTree = JCategories::getInstance('com_content');
  33. $category = $categoryTree->get($catid);
  34. $catids = array();
  35. $catids[] = $category->id;
  36. while($category->getParent() instanceof JCategoryNode)
  37. {
  38. $category = $category->getParent();
  39. $catids[] = $category->id;
  40. }
  41. $catids = array_reverse($catids);
  42. } else {
  43. $catids = array();
  44. }
  45. $needles = array(
  46. 'article' => (int) $id,
  47. 'category' => $catids
  48. );
  49. //Create the link
  50. $link = 'index.php?option=com_content&view=article&id='. $id;
  51. if (is_array($catids)) {
  52. $link .= '&catid='.array_pop($catids);
  53. }
  54. if ($item = ContentHelperRoute::_findItem($needles)) {
  55. $link .= '&Itemid='.$item->id;
  56. };
  57. return $link;
  58. }
  59. public static function getCategoryRoute($catid)
  60. {
  61. jimport('joomla.application.categories');
  62. $categoryTree = JCategories::getInstance('com_content');
  63. $category = $categoryTree->get($catid);
  64. $catids = array();
  65. $catids[] = $category->id;
  66. while($category->getParent() instanceof JCategoryNode)
  67. {
  68. $category = $category->getParent();
  69. $catids[] = $category->id;
  70. }
  71. $catids = array_reverse($catids);
  72. $needles = array(
  73. 'category' => $catids
  74. );
  75. $category = $categoryTree->get($catid);
  76. //Create the link
  77. $link = 'index.php?option=com_content&view=category&id='.$category->slug;
  78. if ($item = ContentHelperRoute::_findItem($needles)) {
  79. if (isset($item->query['layout'])) {
  80. $link .= '&layout='.$item->query['layout'];
  81. }
  82. $link .= '&Itemid='.$item->id;
  83. };
  84. return $link;
  85. }
  86. protected static function _findItem($needles)
  87. {
  88. $component = &JComponentHelper::getComponent('com_content');
  89. $app = JFactory::getApplication();
  90. $menus = & $app->getMenu();
  91. $items = $menus->getItems('component_id', $component->id);
  92. $match = null;
  93. foreach($needles as $needle => $id)
  94. {
  95. if (is_array($id))
  96. {
  97. foreach($id as $tempid)
  98. {
  99. foreach($items as $item)
  100. {
  101. if ((@$item->query['view'] == $needle) && (@$item->query['id'] == $tempid)) {
  102. $match = $item;
  103. break;
  104. }
  105. }
  106. }
  107. } else {
  108. foreach($items as $item)
  109. {
  110. if ((@$item->query['view'] == $needle) && (@$item->query['id'] == $id)) {
  111. $match = $item;
  112. break;
  113. }
  114. }
  115. }
  116. if (isset($match)) {
  117. break;
  118. }
  119. }
  120. return $match;
  121. }
  122. }
  123. ?>