PageRenderTime 26ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/mod_k2_user/helper.php

https://gitlab.com/ppapadatis/Videolearn
PHP | 209 lines | 168 code | 32 blank | 9 comment | 28 complexity | 852c7b1da5273f7a4b6d2ec1e979cf48 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: helper.php 1665 2012-10-01 10:04:50Z lefteris.kavadas $
  4. * @package K2
  5. * @author JoomlaWorks http://www.joomlaworks.net
  6. * @copyright Copyright (c) 2006 - 2012 JoomlaWorks Ltd. All rights reserved.
  7. * @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
  8. */
  9. // no direct access
  10. defined('_JEXEC') or die ;
  11. JLoader::register('K2HelperRoute', JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'route.php');
  12. JLoader::register('K2HelperUtilities', JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'utilities.php');
  13. class modK2UserHelper
  14. {
  15. public static function getReturnURL($params, $type)
  16. {
  17. if ($itemid = $params->get($type))
  18. {
  19. $application = JFactory::getApplication();
  20. $menu = $application->getMenu();
  21. $item = $menu->getItem($itemid);
  22. $url = JRoute::_($item->link.'&Itemid='.$itemid, false);
  23. }
  24. else
  25. {
  26. // stay on the same page
  27. $uri = JFactory::getURI();
  28. $url = $uri->toString(array('path', 'query', 'fragment'));
  29. }
  30. return base64_encode($url);
  31. }
  32. public static function getType()
  33. {
  34. $user = JFactory::getUser();
  35. return (!$user->get('guest')) ? 'logout' : 'login';
  36. }
  37. public static function getProfile(&$params)
  38. {
  39. $user = JFactory::getUser();
  40. $db = JFactory::getDBO();
  41. $query = "SELECT * FROM #__k2_users WHERE userID=".(int)$user->id;
  42. $db->setQuery($query, 0, 1);
  43. $profile = $db->loadObject();
  44. if ($profile)
  45. {
  46. if ($profile->image != '')
  47. $profile->avatar = JURI::root().'media/k2/users/'.$profile->image;
  48. require_once (JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'permissions'.'.php');
  49. if (JRequest::getCmd('option') != 'com_k2')
  50. K2HelperPermissions::setPermissions();
  51. if (K2HelperPermissions::canAddItem())
  52. $profile->addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
  53. return $profile;
  54. }
  55. }
  56. public static function countUserComments($userID)
  57. {
  58. $db = JFactory::getDBO();
  59. $query = "SELECT COUNT(*) FROM #__k2_comments WHERE userID=".(int)$userID." AND published=1";
  60. $db->setQuery($query);
  61. $result = $db->loadResult();
  62. return $result;
  63. }
  64. public static function getMenu($params)
  65. {
  66. $items = array();
  67. $children = array();
  68. if ($params->get('menu'))
  69. {
  70. $menu = JSite::getMenu();
  71. $items = $menu->getItems('menutype', $params->get('menu'));
  72. }
  73. foreach ($items as $item)
  74. {
  75. if (K2_JVERSION != '15')
  76. {
  77. $item->name = $item->title;
  78. $item->parent = $item->parent_id;
  79. }
  80. $index = $item->parent;
  81. $list = @$children[$index] ? $children[$index] : array();
  82. array_push($list, $item);
  83. $children[$index] = $list;
  84. }
  85. if (K2_JVERSION != '15')
  86. {
  87. $items = JHTML::_('menu.treerecurse', 1, '', array(), $children, 9999, 0, 0);
  88. }
  89. else
  90. {
  91. $items = JHTML::_('menu.treerecurse', 0, '', array(), $children, 9999, 0, 0);
  92. }
  93. $links = array();
  94. foreach ($items as $item)
  95. {
  96. if (K2_JVERSION == '15')
  97. {
  98. $item->level = $item->sublevel;
  99. switch ($item->type)
  100. {
  101. case 'separator' :
  102. continue;
  103. break;
  104. case 'url' :
  105. if ((strpos($item->link, 'index.php?') === 0) && (strpos($item->link, 'Itemid=') === false))
  106. {
  107. $item->url = $item->link.'&amp;Itemid='.$item->id;
  108. }
  109. else
  110. {
  111. $item->url = $item->link;
  112. }
  113. break;
  114. default :
  115. $router = JSite::getRouter();
  116. $item->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$item->id : $item->link.'&Itemid='.$item->id;
  117. break;
  118. }
  119. $iParams = class_exists('JParameter') ? new JParameter($item->params) : new JRegistry($item->params);
  120. $iSecure = $iParams->def('secure', 0);
  121. if ($item->home == 1)
  122. {
  123. $item->url = JURI::base();
  124. }
  125. elseif (strcasecmp(substr($item->url, 0, 4), 'http') && (strpos($item->link, 'index.php?') !== false))
  126. {
  127. $item->url = JRoute::_($item->url, true, $iSecure);
  128. }
  129. else
  130. {
  131. $item->url = str_replace('&', '&amp;', $item->url);
  132. }
  133. $item->route = $item->url;
  134. }
  135. else
  136. {
  137. $item->flink = $item->link;
  138. switch ($item->type)
  139. {
  140. case 'separator' :
  141. continue;
  142. case 'url' :
  143. if ((strpos($item->link, 'index.php?') === 0) && (strpos($item->link, 'Itemid=') === false))
  144. {
  145. $item->flink = $item->link.'&Itemid='.$item->id;
  146. }
  147. break;
  148. case 'alias' :
  149. $item->flink = 'index.php?Itemid='.$item->params->get('aliasoptions');
  150. break;
  151. default :
  152. $router = JSite::getRouter();
  153. if ($router->getMode() == JROUTER_MODE_SEF)
  154. {
  155. $item->flink = 'index.php?Itemid='.$item->id;
  156. }
  157. else
  158. {
  159. $item->flink .= '&Itemid='.$item->id;
  160. }
  161. break;
  162. }
  163. if (strcasecmp(substr($item->flink, 0, 4), 'http') && (strpos($item->flink, 'index.php?') !== false))
  164. {
  165. $item->flink = JRoute::_($item->flink, true, $item->params->get('secure'));
  166. }
  167. else
  168. {
  169. $item->flink = JRoute::_($item->flink);
  170. }
  171. $item->route = $item->flink;
  172. }
  173. $links[] = $item;
  174. }
  175. return $links;
  176. }
  177. }