1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage HTML
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Utility class for icons.
14 *
15 * @since 3.2
16 */
17 abstract class JHtmlLinks
18 {
19 /**
20 * Method to generate html code for groups of lists of links
21 *
22 * @param array $groupsOfLinks Array of links
23 *
24 * @return string
25 *
26 * @since 3.2
27 */
28 public static function linksgroups($groupsOfLinks)
29 {
30 $html = array();
31
32 if (count($groupsOfLinks) > 0)
33 {
34 $layout = new JLayoutFile('joomla.links.groupsopen');
35 $html[] = $layout->render('');
36
37 foreach ($groupsOfLinks as $title => $links)
38 {
39 if (isset($links[0]['separategroup']))
40 {
41 $layout = new JLayoutFile('joomla.links.groupseparator');
42 $html[] = $layout->render($title);
43 }
44
45 $layout = new JLayoutFile('joomla.links.groupopen');
46 $htmlHeader = $layout->render($title);
47
48 $htmlLinks = JHtml::_('links.links', $links);
49
50 if ($htmlLinks != '')
51 {
52 $html[] = $htmlHeader;
53 $html[] = $htmlLinks;
54
55 $layout = new JLayoutFile('joomla.links.groupclose');
56 $html[] = $layout->render('');
57 }
58 }
59
60 $layout = new JLayoutFile('joomla.links.groupsclose');
61 $html[] = $layout->render('');
62 }
63
64 return implode($html);
65 }
66
67 /**
68 * Method to generate html code for a list of links
69 *
70 * @param array $links Array of links
71 *
72 * @return string
73 *
74 * @since 3.2
75 */
76 public static function links($links)
77 {
78 $html = array();
79
80 foreach ($links as $link)
81 {
82 $html[] = JHtml::_('links.link', $link);
83 }
84
85 return implode($html);
86 }
87
88 /**
89 * Method to generate html code for a single link
90 *
91 * @param array $link link properties
92 *
93 * @return string
94 *
95 * @since 3.2
96 */
97 public static function link($link)
98 {
99 if (isset($link['access']))
100 {
101 if (is_bool($link['access']))
102 {
103 if ($link['access'] == false)
104 {
105 return '';
106 }
107 }
108 else
109 {
110 // Get the user object to verify permissions
111 $user = JFactory::getUser();
112
113 // Take each pair of permission, context values.
114 for ($i = 0, $n = count($link['access']); $i < $n; $i += 2)
115 {
116 if (!$user->authorise($link['access'][$i], $link['access'][$i + 1]))
117 {
118 return '';
119 }
120 }
121 }
122 }
123
124 // Instantiate a new JLayoutFile instance and render the layout
125 $layout = new JLayoutFile('joomla.links.link');
126
127 return $layout->render($link);
128 }
129 }
130