/**
* Generate a list of quickbuttons.
*
* @param array $list_items An array with info for displaying the strip
* @param string $list_class Used for integration hooks and as a class name
*/
function template_quickbuttons($list_items, $list_class = null, $output_method = 'echo')
{
global $txt;
// Enable manipulation with hooks
if (!empty($list_class))
call_integration_hook('integrate_' . $list_class . '_quickbuttons', array(&$list_items));
// Make sure the list has at least one shown item
foreach ($list_items as $key => $li)
{
// Is there a sublist, and does it have any shown items
if ($key == 'more')
{
foreach ($li as $subkey => $subli)
if (isset($subli['show']) && !$subli['show'])
unset($list_items[$key][$subkey]);
if (empty($list_items[$key]))
unset($list_items[$key]);
}
// A normal list item
elseif (isset($li['show']) && !$li['show'])
unset($list_items[$key]);
}
// Now check if there are any items left
if (empty($list_items))
return;
// Print the quickbuttons
$output = '
<ul class="quickbuttons' . (!empty($list_class) ? ' quickbuttons_' . $list_class : '') . '">';
// This is used for a list item or a sublist item
$list_item_format = function($li)
{
$html = '
<li' . (!empty($li['class']) ? ' class="' . $li['class'] . '"' : '') . (!empty($li['id']) ? ' id="' . $li['id'] . '"' : '') . (!empty($li['custom']) ? $li['custom'] : '') . '>';
if (isset($li['content']))
$html .= $li['content'];
else
$html .= '
<a' . (!empty($li['href']) ? ' href="' . $li['href'] . '"' : '') . (!empty($li['javascript']) ? $li['javascript'] : '') . '>
' . (!empty($li['icon']) ? '<span class="main_icons ' . $li['icon'] . '"></span>' : '') . (!empty($li['label']) ? $li['label'] : '') . '
</a>';
$html .= '
</li>';
return $html;
};
foreach ($list_items as $key => $li)
{
// Handle the sublist
if ($key == 'more')
{
$output .= '
<li class="post_options">' . $txt['post_options'] . '
<ul>';
foreach ($li as $subli)
$output .= $list_item_format($subli);
$output .= '
</ul>
</li>';
}
// Ordinary list item
else
$output .= $list_item_format($li);
}
$output .= '
</ul><!-- .quickbuttons -->';
// There are a few spots where the result needs to be returned
if ($output_method == 'echo')
echo $output;
else
return $output;
}