PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_contact/helpers/route.php

https://github.com/joebushi/joomla
PHP | 78 lines | 46 code | 13 blank | 19 comment | 7 complexity | 7a5b645c0e9a6842df7e502239a7877d 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. * Contact Component Route Helper
  16. *
  17. * @static
  18. * @package Joomla
  19. * @subpackage com_contact
  20. * @since 1.6
  21. */
  22. class ContactHelperRoute
  23. {
  24. function getContactRoute($id, $catid) {
  25. $needles = array(
  26. 'category' => (int) $catid,
  27. 'categories' => null
  28. );
  29. //Find the itemid
  30. $itemid = ContactHelperRoute::_findItem($needles);
  31. $itemid = $itemid ? '&Itemid='.$itemid : '';
  32. //Create the link
  33. $link = 'index.php?option=com_contact&view=contact&id='. $id . '&catid='.$catid . $itemid;
  34. return $link;
  35. }
  36. function _findItem($needles)
  37. {
  38. static $items;
  39. if (!$items)
  40. {
  41. $component = &JComponentHelper::getComponent('com_contact');
  42. $menu = &JSite::getMenu();
  43. $items = $menu->getItems('component_id', $component->id);
  44. }
  45. if (!is_array($items)) {
  46. return null;
  47. }
  48. $match = null;
  49. foreach($needles as $needle => $id)
  50. {
  51. foreach($items as $item)
  52. {
  53. if ((@$item->query['view'] == $needle) && (@$item->query['id'] == $id)) {
  54. $match = $item->id;
  55. break;
  56. }
  57. }
  58. if (isset($match)) {
  59. break;
  60. }
  61. }
  62. return $match;
  63. }
  64. }
  65. ?>