/modules/mod_login/helper.php

https://github.com/dextercowley/joomla-cms · PHP · 122 lines · 75 code · 13 blank · 34 comment · 11 complexity · cdd9ee827a7cdc585c851635d8e47aa4 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Site
  4. * @subpackage mod_login
  5. *
  6. * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * Helper for mod_login
  12. *
  13. * @package Joomla.Site
  14. * @subpackage mod_login
  15. *
  16. * @since 1.5
  17. */
  18. class ModLoginHelper
  19. {
  20. /**
  21. * Retrieve the url where the user should be returned after logging in
  22. *
  23. * @param JRegistry $params module parameters
  24. * @param string $type return type
  25. *
  26. * @return string
  27. */
  28. public static function getReturnURL($params, $type)
  29. {
  30. $app = JFactory::getApplication();
  31. $router = $app->getRouter();
  32. $url = null;
  33. if ($itemid = $params->get($type))
  34. {
  35. $db = JFactory::getDbo();
  36. $query = $db->getQuery(true)
  37. ->select($db->quoteName('link'))
  38. ->from($db->quoteName('#__menu'))
  39. ->where($db->quoteName('published') . '=1')
  40. ->where($db->quoteName('id') . '=' . $db->quote($itemid));
  41. $db->setQuery($query);
  42. if ($link = $db->loadResult())
  43. {
  44. if ($router->getMode() == JROUTER_MODE_SEF)
  45. {
  46. $url = 'index.php?Itemid=' . $itemid;
  47. }
  48. else
  49. {
  50. $url = $link . '&Itemid=' . $itemid;
  51. }
  52. }
  53. }
  54. if (!$url)
  55. {
  56. // Stay on the same page
  57. $uri = clone JUri::getInstance();
  58. $vars = $router->parse($uri);
  59. unset($vars['lang']);
  60. if ($router->getMode() == JROUTER_MODE_SEF)
  61. {
  62. if (isset($vars['Itemid']))
  63. {
  64. $itemid = $vars['Itemid'];
  65. $menu = $app->getMenu();
  66. $item = $menu->getItem($itemid);
  67. unset($vars['Itemid']);
  68. if (isset($item) && $vars == $item->query)
  69. {
  70. $url = 'index.php?Itemid=' . $itemid;
  71. }
  72. else
  73. {
  74. $url = 'index.php?' . JUri::buildQuery($vars) . '&Itemid=' . $itemid;
  75. }
  76. }
  77. else
  78. {
  79. $url = 'index.php?' . JUri::buildQuery($vars);
  80. }
  81. }
  82. else
  83. {
  84. $url = 'index.php?' . JUri::buildQuery($vars);
  85. }
  86. }
  87. return base64_encode($url);
  88. }
  89. /**
  90. * Returns the current users type
  91. *
  92. * @return string
  93. */
  94. public static function getType()
  95. {
  96. $user = JFactory::getUser();
  97. return (!$user->get('guest')) ? 'logout' : 'login';
  98. }
  99. /**
  100. * Get list of available two factor methods
  101. *
  102. * @return array
  103. */
  104. public static function getTwoFactorMethods()
  105. {
  106. require_once JPATH_ADMINISTRATOR . '/components/com_users/helpers/users.php';
  107. return UsersHelper::getTwoFactorMethods();
  108. }
  109. }