PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_hwdmediashare/helpers/navigation.php

https://gitlab.com/ppapadatis/Videolearn
PHP | 292 lines | 203 code | 38 blank | 51 comment | 45 complexity | 819120a5600d57293817191b181ceea7 MD5 | raw file
  1. <?php
  2. /**
  3. * @version SVN $Id: navigation.php 496 2012-08-29 13:26:32Z dhorsfall $
  4. * @package hwdMediaShare
  5. * @copyright Copyright (C) 2011 Highwood Design Limited. All rights reserved.
  6. * @license GNU General Public License http://www.gnu.org/copyleft/gpl.html
  7. * @author Dave Horsfall
  8. * @since 14-Nov-2011 20:36:41
  9. */
  10. // No direct access to this file
  11. defined('_JEXEC') or die('Restricted access');
  12. /**
  13. * hwdMediaShare Navigation Helper
  14. *
  15. * @package hwdMediaShare
  16. * @since 0.1
  17. */
  18. abstract class hwdMediaShareHelperNavigation
  19. {
  20. /**
  21. * Method to insert Javascript declaration for live site variable,
  22. *
  23. * @since 0.1
  24. */
  25. public static function setJavascriptVars()
  26. {
  27. $doc = & JFactory::getDocument();
  28. $js = array();
  29. $js[] = 'var hwdms_live_site = "' . JURI::root() . 'index.php";';
  30. $doc->addScriptDeclaration( implode("\n", $js) );
  31. }
  32. /**
  33. * Method to insert internal navigation using hwdMediaShare Joomla menu,
  34. * or fallback static menu
  35. *
  36. * @since 0.1
  37. */
  38. public static function getInternalNavigation()
  39. {
  40. $app = JFactory::getApplication();
  41. $view = JRequest::getWord('view');
  42. $html = '';
  43. $tmpl = JRequest::getWord( 'tmpl', '' );
  44. JHtml::_('behavior.modal');
  45. // Load hwdMediaShare config
  46. $hwdms = hwdMediaShareFactory::getInstance();
  47. $config = $hwdms->getConfig();
  48. if ($config->get('internal_navigation') != 0 && $tmpl != 'component')
  49. {
  50. JLoader::register('modMenuHelper', JPATH_SITE . '/modules/mod_menu/helper.php');
  51. $params = new JRegistry( '{"menutype":"hwdmediashare","show_title":""}' );
  52. $list = modMenuHelper::getList($params);
  53. $app = JFactory::getApplication();
  54. $menu = $app->getMenu();
  55. $active = $menu->getActive();
  56. $active_id = isset($active) ? $active->id : $menu->getDefault()->id;
  57. $path = isset($active) ? $active->tree : array();
  58. $showAll = $params->get('showAllChildren');
  59. $class_sfx = htmlspecialchars($params->get('class_sfx'));
  60. ob_start();
  61. ?>
  62. <!-- Media Main Navigation -->
  63. <div class="media-mediamenu">
  64. <?php
  65. if(count($list))
  66. {
  67. require JModuleHelper::getLayoutPath('mod_menu', $params->get('layout', 'default'));
  68. }
  69. else
  70. {
  71. ?>
  72. <ul class="menu">
  73. <li class="<?php echo ($view == 'discover' ? 'active ' : false); ?>media-medianav-discover"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=discover'); ?>"><?php echo JText::_('COM_HWDMS_DISCOVER'); ?></a></li>
  74. <li class="<?php echo (($view == 'media' || $view == 'mediaitem') ? 'active ' : false); ?>media-medianav-media"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=media'); ?>"><?php echo JText::_('COM_HWDMS_MEDIA'); ?></a></li>
  75. <li class="<?php echo (($view == 'categories' || $view == 'category') ? 'active ' : false); ?>media-medianav-categories"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=categories'); ?>"><?php echo JText::_('COM_HWDMS_CATEGORIES'); ?></a></li>
  76. <li class="<?php echo (($view == 'albums' || $view == 'album') ? 'active ' : false); ?>media-medianav-albums"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=albums'); ?>"><?php echo JText::_('COM_HWDMS_ALBUMS'); ?></a></li>
  77. <li class="<?php echo (($view == 'groups' || $view == 'group') ? 'active ' : false); ?>media-medianav-groups"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=groups'); ?>"><?php echo JText::_('COM_HWDMS_GROUPS'); ?></a></li>
  78. <li class="<?php echo (($view == 'playlists' || $view == 'playlist') ? 'active ' : false); ?>media-medianav-playlists"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=playlists'); ?>"><?php echo JText::_('COM_HWDMS_PLAYLISTS'); ?></a></li>
  79. <li class="<?php echo (($view == 'users' || $view == 'user') ? 'active ' : false); ?>media-medianav-channels"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=users'); ?>"><?php echo JText::_('COM_HWDMS_USER_CHANNELS'); ?></a></li>
  80. <li class="<?php echo ($view == 'upload' ? 'active ' : false); ?>media-medianav-upload"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=upload'); ?>"><?php echo JText::_('COM_HWDMS_UPLOAD'); ?></a></li>
  81. <li class="<?php echo ($view == 'account' ? 'active ' : false); ?>media-medianav-account"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=account'); ?>"><?php echo JText::_('COM_HWDMS_MY_ACCOUNT'); ?></a></li>
  82. <li class="<?php echo ($view == 'search' ? 'active ' : false); ?>media-medianav-search"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=search'); ?>"><?php echo JText::_('COM_HWDMS_SEARCH'); ?></a></li>
  83. </ul>
  84. <?php
  85. }
  86. ?>
  87. </div>
  88. <?php
  89. $html = ob_get_contents();
  90. ob_end_clean();
  91. }
  92. return $html;
  93. }
  94. /**
  95. * Method to insert accoutn navigation menu,
  96. *
  97. * @since 0.1
  98. */
  99. public static function getAccountNavigation()
  100. {
  101. $user = JFactory::getUser();
  102. $uri = JFactory::getURI();
  103. // Load hwdMediaShare config
  104. $hwdms = hwdMediaShareFactory::getInstance();
  105. $config = $hwdms->getConfig();
  106. ob_start();
  107. ?>
  108. <!-- Media Main Navigation -->
  109. <div class="media-accountmenu">
  110. <ul class="media-accountnav">
  111. <li class="media-accountnav-overview"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=account'); ?>"><?php echo JText::_('COM_HWDMS_OVERVIEW'); ?></a></li>
  112. <li class="media-accountnav-profile"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&task=userform.edit&id='.$user->id.'&return='.base64_encode($uri)); ?>"><?php echo JText::_('COM_HWDMS_PROFILE'); ?></a></li>
  113. <li class="media-accountnav-media"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=account&layout=media'); ?>"><?php echo JText::_('COM_HWDMS_MY_MEDIA'); ?></a></li>
  114. <li class="media-accountnav-favourites"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=account&layout=favourites'); ?>"><?php echo JText::_('COM_HWDMS_MY_FAVOURITES'); ?></a></li>
  115. <?php if ($config->get('enable_albums')): ?><li class="media-accountnav-albums"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=account&layout=albums'); ?>"><?php echo JText::_('COM_HWDMS_MY_ALBUMS'); ?></a></li><?php endif; ?>
  116. <?php if ($config->get('enable_groups')): ?><li class="media-accountnav-groups"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=account&layout=groups'); ?>"><?php echo JText::_('COM_HWDMS_MY_GROUPS'); ?></a></li><?php endif; ?>
  117. <?php if ($config->get('enable_playlists')): ?><li class="media-accountnav-playlists"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=account&layout=playlists'); ?>"><?php echo JText::_('COM_HWDMS_MY_PLAYLISTS'); ?></a></li><?php endif; ?>
  118. <?php if ($config->get('enable_subscriptions')): ?><li class="media-accountnav-subscriptions"><a href="<?php echo JRoute::_('index.php?option=com_hwdmediashare&view=account&layout=subscriptions'); ?>"><?php echo JText::_('COM_HWDMS_MY_SUBSCRIPTIONS'); ?></a></li><?php endif; ?>
  119. </ul>
  120. </div>
  121. <?php
  122. $html = ob_get_contents();
  123. ob_end_clean();
  124. return $html;
  125. }
  126. /**
  127. * @since 0.1
  128. */
  129. public function pageNavigation(&$row, &$params, $page=0)
  130. {
  131. $view = JRequest::getCmd('view');
  132. $print = JRequest::getBool('print');
  133. // Get additional filters
  134. $album_id = JRequest::getCmd('album_id');
  135. if ($print)
  136. {
  137. return false;
  138. }
  139. $nav = new StdClass;
  140. //if ($params->get('show_item_navigation') && ($view == 'article')) {
  141. if ($view == 'mediaitem')
  142. {
  143. $html = '';
  144. $db = JFactory::getDbo();
  145. $user = JFactory::getUser();
  146. $app = JFactory::getApplication();
  147. $lang = JFactory::getLanguage();
  148. $nullDate = $db->getNullDate();
  149. $date = JFactory::getDate();
  150. $config = JFactory::getConfig();
  151. $now = $date->toSql();
  152. $uid = $row->id;
  153. $canPublish = $user->authorise('core.edit.state', 'com_hwdmediashare.media.'.$row->id);
  154. // The following is needed as different menu items types utilise a different param to control ordering.
  155. // For Blogs the `orderby_sec` param is the order controlling param.
  156. // For Table and List views it is the `orderby` param.
  157. $params_list = $params->toArray();
  158. if (array_key_exists('orderby_sec', $params_list)) {
  159. $order_method = $params->get('orderby_sec', '');
  160. } else {
  161. $order_method = $params->get('orderby', '');
  162. }
  163. // Additional check for invalid sort ordering.
  164. if ($order_method == 'front') {
  165. $order_method = '';
  166. }
  167. // Determine sort order.
  168. switch ($order_method) {
  169. case 'date' :
  170. $orderby = 'a.created';
  171. break;
  172. case 'rdate' :
  173. $orderby = 'a.created DESC';
  174. break;
  175. case 'alpha' :
  176. $orderby = 'a.title';
  177. break;
  178. case 'ralpha' :
  179. $orderby = 'a.title DESC';
  180. break;
  181. case 'hits' :
  182. $orderby = 'a.hits';
  183. break;
  184. case 'rhits' :
  185. $orderby = 'a.hits DESC';
  186. break;
  187. case 'order' :
  188. $orderby = 'a.ordering';
  189. break;
  190. case 'author' :
  191. $orderby = 'a.created_by_alias, u.name';
  192. break;
  193. case 'rauthor' :
  194. $orderby = 'a.created_by_alias DESC, u.name DESC';
  195. break;
  196. case 'front' :
  197. $orderby = 'f.ordering';
  198. break;
  199. default :
  200. $orderby = 'a.ordering';
  201. break;
  202. }
  203. $xwhere = ' AND (a.published = 1 OR a.published = -1)' .
  204. ' AND (publish_up = '.$db->Quote($nullDate).' OR publish_up <= '.$db->Quote($now).')' .
  205. ' AND (publish_down = '.$db->Quote($nullDate).' OR publish_down >= '.$db->Quote($now).')' .
  206. ' AND (a.private = 0 OR (a.private = 1 && a.created_user_id = '.$user->id.'))';
  207. // Array of media (in same category) correctly ordered.
  208. $query = $db->getQuery(true);
  209. $query->select('a.id, a.title, a.key, a.ext_id, a.thumbnail_ext_id, a.type, a.thumbnail');
  210. $query->from('#__hwdms_media AS a');
  211. //$query->leftJoin('#__categories AS cc ON cc.id = a.catid');
  212. //$query->where('a.catid = '. (int)$row->catid .' AND a.state = '. (int)$row->state
  213. // . ($canPublish ? '' : ' AND a.access = ' .(int)$row->access) . $xwhere);
  214. if ($album_id)
  215. {
  216. $query->leftJoin('#__hwdms_album_map AS amap ON amap.media_id = a.id');
  217. $query->where('amap.album_id = '. (int)$album_id);
  218. }
  219. $query->where('(a.published = 1 OR a.published = -1)');
  220. $query->where('(publish_up = '.$db->Quote($nullDate).' OR publish_up <= '.$db->Quote($now).')');
  221. $query->where('(publish_down = '.$db->Quote($nullDate).' OR publish_down >= '.$db->Quote($now).')');
  222. $query->where('(a.private = 0 OR (a.private = 1 && a.created_user_id = '.$user->id.'))');
  223. $query->order($orderby);
  224. if ($app->isSite() && $app->getLanguageFilter())
  225. {
  226. $query->where('a.language in ('.$db->quote($lang->getTag()).','.$db->quote('*').')');
  227. }
  228. $db->setQuery($query);
  229. $list = $db->loadObjectList('id');
  230. // This check needed if incorrect Itemid is given resulting in an incorrect result.
  231. if (!is_array($list))
  232. {
  233. $list = array();
  234. }
  235. reset($list);
  236. // Location of current content item in array list.
  237. $location = array_search($uid, array_keys($list));
  238. $navs = array_values($list);
  239. $nav->prev = null;
  240. $nav->next = null;
  241. if ($location -1 >= 0)
  242. {
  243. // The previous content item cannot be in the array position -1.
  244. $nav->prev = $navs[$location -1];
  245. }
  246. if (($location +1) < count($navs))
  247. {
  248. // The next content item cannot be in an array position greater than the number of array postions.
  249. $nav->next = $navs[$location +1];
  250. }
  251. }
  252. return $nav;
  253. }
  254. }