示例#1
0
 function getUrl($params)
 {
     global $prefs;
     if ($prefs['feature_sefurl'] == 'y') {
         $url = "tiki-{$params['controller']}";
         if (isset($params['action'])) {
             $url .= "-{$params['action']}";
         } else {
             $url .= "-x";
         }
         unset($params['controller']);
         unset($params['action']);
     } else {
         $url = 'tiki-ajax_services.php';
     }
     if (count($params)) {
         $url .= '?' . http_build_query($params, '', '&');
     }
     return TikiLib::tikiUrlOpt($url);
 }
示例#2
0
function smarty_block_pagination_links($params, $url, $smarty, &$repeat)
{
    global $prefs;
    if ($repeat) {
        return;
    }
    if (isset($params['resultset'])) {
        $resultSet = $params['resultset'];
        $params['cant'] = count($resultSet);
        $params['offset'] = $resultSet->getOffset();
        $params['step'] = $resultSet->getMaxRecords();
        $params['estimate'] = $resultSet->getEstimate();
    }
    $html = '';
    $default_type = 'absolute_path';
    // Check main params and return no pagination links if there is a mistake
    if (!isset($params['cant']) || $params['cant'] <= 0) {
        return '';
    }
    if (isset($params['step']) && $params['step'] == -1) {
        return '';
    }
    // display all
    if (!isset($params['offset'])) {
        $params['offset'] = 0;
    }
    if (!isset($params['offset_arg'])) {
        $params['offset_arg'] = 'offset';
    }
    if (!isset($params['zero_based_offset'])) {
        $params['zero_based_offset'] = 'y';
    }
    if (!isset($params['show_numbers'])) {
        $params['show_numbers'] = 'y';
    }
    if (!isset($params['_onclick'])) {
        $params['_onclick'] = '';
    }
    if ($params['zero_based_offset'] != 'y') {
        //$params['offset']--;
        $zero_based_min = 1;
        $zero_based_maxminus = 0;
    } else {
        $zero_based_min = 0;
        $zero_based_maxminus = 1;
    }
    $params['_ajax'] = isset($params['_ajax']) ? $params['_ajax'] : 'y';
    if (isset($params['reloff']) && ($params['reloff'] + $params['offset'] >= $params['cant'] || $params['reloff'] + $params['offset'] < $zero_based_min)) {
        return '';
    }
    if (!isset($params['reloff']) && ($params['offset'] >= $params['cant'] + $zero_based_min || $params['offset'] < $zero_based_min)) {
        return '';
    }
    // Include smarty functions used below
    $smarty->loadPlugin('smarty_block_ajax_href');
    $smarty->loadPlugin('smarty_function_query');
    $smarty->loadPlugin('smarty_function_icon');
    // Make sure every params are initialized
    if (!isset($params['itemname'])) {
        $params['itemname'] = 'Page';
    }
    if (!isset($params['noimg'])) {
        $params['noimg'] = $prefs['pagination_icons'] == 'n' ? 'y' : 'n';
    }
    if (!isset($params['usedots'])) {
        $params['usedots'] = 'y';
    }
    if (!isset($params['class'])) {
        $params['class'] = 'mini';
    }
    if (!isset($params['htmlelement'])) {
        $params['htmlelement'] = 'tiki-center';
    }
    if (!isset($params['template'])) {
        $params['template'] = basename($_SERVER['PHP_SELF'], '.php') . '.tpl';
        if ($params['template'] == 'tiki-index.tpl') {
            $params['template'] = 'tiki-show_page.tpl';
        }
    }
    if (!file_exists('templates/' . $params['template']) || $params['template'] == 'noauto') {
        $params['htmlelement'] = '';
        $params['template'] = '';
    }
    if (!isset($params['step']) || $params['step'] <= 0) {
        $params['step'] = 1;
        $nb_pages = $params['cant'];
    } else {
        $nb_pages = ceil($params['cant'] / $params['step']);
    }
    if ($nb_pages == 0 || $nb_pages == 1 && $prefs['pagination_hide_if_one_page'] == 'y') {
        return '';
    }
    if (empty($url) || preg_match('/^\\s*$/', $url)) {
        $query_filter = array('_type' => $default_type);
        if (isset($params['_keepall'])) {
            $query_filter['_keepall'] = $params['_keepall'];
        }
        $url = smarty_function_query($query_filter, $smarty);
    }
    // remove empty url arguments (done by default)
    if (!isset($params['clean']) || $params['clean'] == 'y') {
        $url = preg_replace('/(?<=\\?|&amp;)[^=]+=(?=&amp;|$)/U', '', $url);
    }
    // remove old arguments that will be replaced and add new ones
    $url = preg_replace('/(?<=&amp;|&|\\?)(move|reloff|' . $params['offset_arg'] . ')=[^&]*/', '', trim($url));
    // remove &amp; that are redundant or at the end of url
    $url = preg_replace('/(?:(\\?|&amp;)(&amp;)+|(\\?|&amp;))$/', '\\1', $url);
    $url_args_pos = strpos($url, '?');
    if ($url_args_pos === false) {
        $url .= '?';
    } elseif ($url_args_pos < strlen($url) - 1) {
        $url .= '&amp;';
    }
    if (isset($params['reloff'])) {
        $prev_offset = 'reloff=' . ($params['reloff'] - $params['step']) . '&amp;' . $params['offset_arg'] . '=' . $params['offset'];
        $next_offset = 'reloff=' . ($params['reloff'] + $params['step']) . '&amp;' . $params['offset_arg'] . '=' . $params['offset'];
        $prev_fast_offset = 'reloff=' . ($params['reloff'] - $params['step'] * ceil($nb_pages / 10)) . '&amp;' . $params['offset_arg'] . '=' . $params['offset'];
        $next_fast_offset = 'reloff=' . ($params['reloff'] + $params['step'] * ceil($nb_pages / 10)) . '&amp;' . $params['offset_arg'] . '=' . $params['offset'];
        $real_offset = $params['offset'] + $params['reloff'];
    } else {
        $prev_offset_val = max($zero_based_min, $params['offset'] - $params['step']);
        $prev_offset = $params['offset_arg'] . '=' . $prev_offset_val;
        $next_offset_val = min($params['cant'] - $zero_based_maxminus, $params['offset'] + $params['step']);
        $next_offset = $params['offset_arg'] . '=' . $next_offset_val;
        $prev_fast_offset_val = max($zero_based_min, $params['offset'] - $params['step'] * ceil($nb_pages / 10));
        $prev_fast_offset = $params['offset_arg'] . '=' . $prev_fast_offset_val;
        $next_fast_offset_val = min($params['cant'] - $zero_based_maxminus, $params['offset'] + $params['step'] * ceil($nb_pages / 10));
        $next_fast_offset = $params['offset_arg'] . '=' . $next_fast_offset_val;
        $real_offset = $params['offset'];
    }
    if (!isset($params['next'])) {
        $params['next'] = $real_offset < ($nb_pages - $zero_based_maxminus) * $params['step'] ? 'y' : 'n';
    }
    if (!isset($params['prev'])) {
        $params['prev'] = $real_offset > $zero_based_min ? 'y' : 'n';
    }
    // Max. number of links when using direct pagination
    $max_middle_links = max(0, $prefs['direct_pagination_max_middle_links']);
    $max_ending_links = $prefs['pagination_firstlast'] != 'n' ? max(0, $prefs['direct_pagination_max_ending_links']) : 0;
    $max_links = (1 + $max_ending_links + $max_middle_links) * 2 + 1;
    // Handle next/prev images
    if ($params['noimg'] == 'n') {
        $tmp = array('first' => tr("First %0", $params['itemname']), 'last' => tr("Last %0", $params['itemname']), 'next' => tr("Next %0", $params['itemname']), 'previous' => tr("Prev %0", $params['itemname']), 'next_fast' => tra('Fast Next'), 'previous_fast' => tra('Fast Prev'));
        $images = array();
        foreach ($tmp as $ik => $iv) {
            $images[$ik] = smarty_function_icon(array('_id' => 'resultset_' . $ik, 'alt' => $iv, 'style' => 'vertical-align:middle;'), $smarty);
        }
        unset($tmp);
    }
    if ($params['cant'] > 0) {
        $make_prevnext_link = function ($url, $content, $params, $class = 'prevnext', $linkoffset) {
            $smarty = TikiLib::lib('smarty');
            $link = '<a class="' . $class . '" ';
            $url = TikiLib::tikiUrlOpt($url);
            if ($params['_ajax'] == 'y') {
                // setting javascript offset variable if requested
                if (!empty($params['offset_jsvar'])) {
                    $params['_onclick'] = $params['offset_jsvar'] . "={$linkoffset};" . $params['_onclick'];
                }
                $link .= smarty_block_ajax_href(array('template' => $params['template'], 'htmlelement' => $params['htmlelement'], '_ajax' => $params['_ajax'], '_onclick' => $params['_onclick']), $url, $smarty, false);
            } else {
                $link .= " href=\"{$url}\" ";
            }
            $link .= '>' . $content . '</a>';
            return $link;
        };
        if (($prefs['direct_pagination'] == 'y' || $prefs['nextprev_pagination'] === 'y') && $nb_pages > 1) {
            $html .= '<ul class="pagination">';
            if ($prefs['nextprev_pagination'] != 'n' || $params['show_numbers'] !== 'y') {
                if ($params['offset'] == 0) {
                    $html .= '<li class="disabled"><span>&laquo;</span></li>';
                } else {
                    $html .= '<li>' . $make_prevnext_link($url . $prev_offset, '&laquo;', $params, 'prevnext prev', $prev_offset_val) . '</li>';
                }
            }
            if ($params['show_numbers'] == 'y') {
                $last_dots = false;
                $page_num = floor($real_offset / $params['step']);
                foreach (range(0, $nb_pages - 1) as $k) {
                    if ($k + $zero_based_min == $page_num) {
                        $html .= '<li class="active"><span>' . ($k + 1) . ' <span class="sr-only">(' . tr('current') . ')</span></span></li>';
                        $last_dots = false;
                    } elseif ($params['usedots'] != 'y' || $params['usedots'] == 'y' && ($nb_pages <= $max_links || $k <= $max_ending_links && $prefs['pagination_firstlast'] != 'n' || $k >= $nb_pages - $max_ending_links - 1 && $prefs['pagination_firstlast'] != 'n' || abs($page_num - $k) <= $max_middle_links || $prefs['pagination_fastmove_links'] == 'y' && abs($page_num - $k) == ceil($nb_pages / 10))) {
                        if (isset($params['reloff'])) {
                            $url_k = $params['offset_arg'] . '=' . $params['offset'] . '&amp;reloff=' . ($params['step'] * $k - $params['offset']);
                        } else {
                            $url_k_val = $params['step'] * ($k + $zero_based_min);
                            $url_k = $params['offset_arg'] . '=' . $url_k_val;
                        }
                        $html .= '<li>' . $make_prevnext_link($url . $url_k, $k + 1, $params, 'prevnext', $url_k_val) . '</li>';
                        $last_dots = false;
                    } elseif (!$last_dots) {
                        $html .= '<li class="disabled"><span>&hellip;</span>';
                        $last_dots = true;
                    }
                }
            }
            if ($prefs['nextprev_pagination'] != 'n' || $params['show_numbers'] !== 'y') {
                if ($params['offset'] + $params['step'] >= $params['cant']) {
                    $html .= '<li class="disabled"><span>&raquo;</span></li>';
                } else {
                    $html .= '<li>' . $make_prevnext_link($url . $next_offset, '&raquo;', $params, 'prevnext next', $next_offset_val) . '</li>';
                }
            }
            $html .= '</ul>';
        }
        if (isset($params['estimate']) && $params['estimate'] > $params['cant']) {
            $html .= '<div class="alert alert-info">' . tr('More results may be available. Refine criteria to access the estimated %0 results.', $params['estimate']) . '</div>';
        }
    }
    return $html;
}
示例#3
0
function smarty_function_object_link_default($smarty, $object, $title = null, $type = 'wiki page', $url = null, $params = array())
{
    global $base_url;
    $smarty->loadPlugin('smarty_modifier_sefurl');
    $smarty->loadPlugin('smarty_modifier_escape');
    $smarty->loadPlugin('smarty_modifier_addongroupname');
    if (empty($title)) {
        $title = TikiLib::lib('object')->get_title($type, $object);
    }
    if (empty($title) && !empty($params['backuptitle'])) {
        $title = $params['backuptitle'];
    }
    if (empty($title) && $type == 'freetag') {
        // Blank freetag should not be returned with "No title specified"
        return '';
    }
    // get add on object title if needed
    $title = smarty_modifier_addongroupname($title);
    $text = $title;
    $titleAttribute = '';
    if ($type == 'wiki page') {
        $titleAttribute .= ' title="' . smarty_modifier_escape($title) . '"';
        $text = TikiLib::lib('wiki')->get_without_namespace($title);
    }
    $escapedText = smarty_modifier_escape($text ? $text : tra('No title specified'));
    if ($url) {
        $escapedHref = smarty_modifier_escape(TikiLib::tikiUrlOpt($url));
    } else {
        $escapedHref = smarty_modifier_escape(smarty_modifier_sefurl($object, $type));
    }
    $classList = array();
    if ($type == "blog post") {
        $classList[] = "link";
    } elseif ($type == "freetag") {
        $classList[] = 'freetag';
    }
    $metadata = TikiLib::lib('object')->get_metadata($type, $object, $classList);
    if (!empty($params['class'])) {
        $classList[] = $params['class'];
    }
    $class = ' class="' . implode(' ', $classList) . '"';
    if (strpos($escapedHref, '://') === false) {
        //$html = '<a href="' . $base_url . $escapedHref . '"' . $class . $titleAttribute . $metadata . '>' . $escapedText . '</a>';
        // When the link is created for a tiki page, then we do NOT want the baseurl included,
        // because it might be we are using a reverse proxy or a an ssl offloader, or we access from a public fqdn that is not
        // configured for teh ip adress we run our webserver.
        // Eaxmple: Fqdn = tiki.mydomain.com -> port forwarding/nat to: 192.168.1.110.
        // In this case links should NOT be generated as absolut urls pointing to  192.168.1.110 which would be the part of the baseUrl.
        $html = '<a href="' . $escapedHref . '"' . $class . $titleAttribute . $metadata . '>' . $escapedText . '</a>';
    } else {
        $html = '<a rel="external" href="' . $escapedHref . '"' . $class . $titleAttribute . $metadata . '>' . $escapedText . '</a>';
    }
    $attributelib = TikiLib::lib('attribute');
    $attributes = $attributelib->get_attributes($type, $object);
    global $prefs;
    if (isset($attributes['tiki.content.source']) && $prefs['fgal_source_show_refresh'] == 'y') {
        $smarty->loadPlugin('smarty_function_icon');
        $smarty->loadPlugin('smarty_function_service');
        $html .= '<a class="file-refresh" href="' . smarty_function_service(array('controller' => 'file', 'action' => 'refresh', 'fileId' => intval($object)), $smarty) . '">' . smarty_function_icon(array('_id' => 'arrow_refresh'), $smarty) . '</a>';
        TikiLib::lib('header')->add_js('
			$(".file-refresh").removeClass("file-refresh").click(function () {
			$.getJSON($(this).attr("href"));
			$(this).remove();
			return false;
		});');
    }
    return $html;
}
示例#4
0
function smarty_modifier_sefurl($source, $type = 'wiki', $with_next = '', $all_langs = '', $with_title = 'y', $title = '')
{
    global $prefs;
    $wikilib = TikiLib::lib('wiki');
    $tikilib = TikiLib::lib('tiki');
    $smarty = TikiLib::lib('smarty');
    $sefurl = $prefs['feature_sefurl'] == 'y';
    switch ($type) {
        case 'wiki page':
        case 'wikipage':
            $type = 'wiki';
            break;
        case 'blog post':
            $type = 'blogpost';
            break;
    }
    switch ($type) {
        case 'wiki':
            return TikiLib::tikiUrlOpt($wikilib->sefurl($source, $with_next, $all_langs));
        case 'blog':
            $href = $sefurl ? "blog{$source}" : "tiki-view_blog.php?blogId={$source}";
            break;
        case 'blogpost':
            $href = $sefurl ? "blogpost{$source}" : "tiki-view_blog_post.php?postId={$source}";
            break;
        case 'calendar':
            $href = $sefurl ? "cal{$source}" : "tiki-calendar.php?calIds[]={$source}";
            break;
        case 'gallery':
            $href = 'tiki-browse_gallery.php?galleryId=' . $source;
            break;
        case 'article':
            $href = $sefurl ? "article{$source}" : "tiki-read_article.php?articleId={$source}";
            break;
        case 'topic':
            $href = "tiki-view_articles.php?topic={$source}";
            break;
        case 'file':
        case 'thumbnail':
        case 'display':
        case 'preview':
            $attributelib = TikiLib::lib('attribute');
            $attributes = $attributelib->get_attributes('file', $source);
            if ($type == 'file') {
                $prefix = 'dl';
                $suffix = null;
            } else {
                $prefix = $type;
                $suffix = '&amp;' . $type;
            }
            if (isset($attributes['tiki.content.url'])) {
                $href = $attributes['tiki.content.url'];
            } else {
                $href = $sefurl ? "{$prefix}{$source}" : "tiki-download_file.php?fileId={$source}{$suffix}";
            }
            break;
        case 'draft':
            $href = 'tiki-download_file.php?fileId=' . $source . '&amp;draft';
            break;
        case 'tracker item':
            $type = 'trackeritem';
        case 'trackeritem':
            $replacementpage = '';
            if ($prefs["feature_sefurl_tracker_prefixalias"] == 'y') {
                $trklib = TikiLib::lib('trk');
                $replacementpage = $trklib->get_trackeritem_pagealias($source);
            }
            if ($replacementpage) {
                return TikiLib::tikiUrlOpt($wikilib->sefurl($replacementpage, $with_next, $all_langs));
            } else {
                $href = 'tiki-view_tracker_item.php?itemId=' . $source;
            }
            break;
        case 'tracker':
            if ($source) {
                $href = 'tiki-view_tracker.php?trackerId=' . $source;
            } else {
                $href = 'tiki-list_trackers.php';
            }
            break;
        case 'filegallery':
        case 'file gallery':
            $href = 'tiki-list_file_gallery.php?galleryId=' . $source;
            break;
        case 'forum':
            $href = $sefurl ? "forum{$source}" : 'tiki-view_forum.php?forumId=' . $source;
            break;
        case 'forumthread':
        case 'forum post':
            // used in unified search getSupportedTypes()
            $href = $sefurl ? "forumthread{$source}" : 'tiki-view_forum_thread.php?comments_parentId=' . $source;
            break;
        case 'image':
            $href = 'tiki-browse_image.php?imageId=' . $source;
            break;
        case 'sheet':
            $href = $sefurl ? "sheet{$source}" : "tiki-view_sheets.php?sheetId={$source}";
            break;
        case 'category':
            $href = $sefurl ? "cat{$source}" : "tiki-browse_categories.php?parentId={$source}";
            break;
        case 'freetag':
            $href = "tiki-browse_freetags.php?tag=" . urlencode($source);
            break;
        case 'newsletter':
            $href = "tiki-newsletters.php?nlId=" . urlencode($source);
            break;
        case 'survey':
            $href = "tiki-take_survey.php?surveyId=" . urlencode($source);
            break;
        default:
            $href = $source;
            break;
    }
    if ($with_next && ($with_title != 'y' || $prefs['feature_sefurl'] !== 'y')) {
        $href .= '&amp;';
    }
    if ($prefs['feature_sefurl'] == 'y' && $smarty) {
        include_once 'tiki-sefurl.php';
        return TikiLib::tikiUrlOpt(filter_out_sefurl($href, $type, $title, $with_next, $with_title));
    } else {
        return TikiLib::tikiUrlOpt($href);
    }
}
示例#5
0
        $base_uri = $base_host;
        // maybe better than nothing
    }
}
if (strpos($base_uri, $tikiroot . 'route.php') !== false && !empty($inclusion)) {
    $base_uri = $base_url . $inclusion;
    if (!empty($_GET)) {
        $base_uri .= '?' . http_build_query($_GET, '', '&');
    }
    global $section, $sections;
    include_once 'tiki-sefurl.php';
    if (isset($sections[$section]['objectType'])) {
        $objectType = $sections[$section]['objectType'];
    } else {
        $objectType = $section;
    }
    if ($objectType === 'wiki page') {
        $objectType = 'wiki';
    }
    $base_uri = TikiLib::tikiUrlOpt(filter_out_sefurl($base_uri, $objectType));
}
// SSL options
if (isset($_REQUEST['stay_in_ssl_mode_present']) || isset($_REQUEST['stay_in_ssl_mode'])) {
    // We stay in HTTPS / SSL mode if 'stay_in_ssl_mode' has an 'y' or 'on' value
    $stay_in_ssl_mode = isset($_REQUEST['stay_in_ssl_mode']) && $_REQUEST['stay_in_ssl_mode'] == 'y' || isset($_REQUEST['stay_in_ssl_mode']) && $_REQUEST['stay_in_ssl_mode'] == 'on' ? 'y' : 'n';
} else {
    // Set default value of 'stay_in_ssl_mode' to the current mode state
    $stay_in_ssl_mode = $https_mode ? 'y' : 'n';
}
// Show the 'Stay in SSL mode' checkbox only if we are already in HTTPS
$show_stay_in_ssl_mode = $https_mode || $prefs['https_login'] == 'required' ? 'y' : 'n';
示例#6
0
function smarty_function_icon($params, $smarty)
{
    if (!is_array($params)) {
        $params = array();
    }
    global $prefs, $tc_theme, $tc_theme_option, $url_path, $base_url, $tikipath, $iconset;
    $cachelib = TikiLib::lib('cache');
    if (empty($tc_theme)) {
        $current_theme = !empty($prefs['theme']) ? $prefs['theme'] : '';
        $current_theme_option = isset($prefs['theme_option']) ? $prefs['theme_option'] : '';
    } else {
        $current_theme = $tc_theme;
        $current_theme_option = !empty($tc_theme_option) ? $tc_theme_option : '';
    }
    if (isset($params['_type'])) {
        if ($params['_type'] === 'absolute_uri') {
            $params['path_prefix'] = $base_url;
        } else {
            if ($params['_type'] === 'absolute_path') {
                $params['path_prefix'] = $url_path;
            }
        }
    }
    $serialized_params = serialize(array_merge($params, array($current_theme, $current_theme_option, isset($_SERVER['HTTPS']))));
    $cache_key = TikiLib::contextualizeKey('icons_' . '_' . md5($serialized_params), 'language', 'external');
    if ($cached = $cachelib->getCached($cache_key)) {
        return $cached;
    }
    $basedirs = array('img/icons', 'img/icons/mime');
    $icons_extension = empty($params['_extension']) ? '.png' : '.' . $params['_extension'];
    $tag = 'img';
    $notag = false;
    $default_class = 'icon';
    $default_width = 16;
    $default_height = 16;
    $menu_text = false;
    $menu_icon = false;
    $confirm = '';
    $html = '';
    if (empty($params['_id'])) {
        if (isset($params['_defaultdir']) && $params['_defaultdir'] == 'img/icons/large') {
            $params['_id'] = 'green_question48x48';
        } else {
            $params['_id'] = 'green_question';
        }
    }
    if (!empty($params['_defaultdir'])) {
        array_unshift($basedirs, $params['_defaultdir']);
        if ($params['_defaultdir'] == 'img/icons/large') {
            $default_width = $default_height = strpos($params['_id'], '48x48') !== false ? 48 : 32;
        }
    }
    // ICONSET START, work-in-progress, more information: dev.tiki.org/icons. $iconset array is prepared by lib/setup/theme.php
    // N.B. In some contexts such as the console $iconset may not be set up
    if (!empty($params['name']) && empty($params['_tag']) && !empty($iconset)) {
        $name = $params['name'];
        $html = $iconset->getHtml($name, $params);
        $menu_text = isset($params['_menu_text']) && $params['_menu_text'] == 'y';
        if (!empty($params['href']) || !empty($params['title']) || $menu_text) {
            /* Generate a link for the icon if href or title (for tips) parameter is set.
             * This will produce a link element (<a>) around the icon.
             * If you want a button element (<button>), use the {button} smarty_tiki function */
            //collect link components
            if (!empty($params['title'])) {
                //add title if not empty
                $a_title = $params['title'];
            } elseif (!empty($params['alt'])) {
                $a_title = $params['alt'];
            } else {
                $a_title = '';
            }
            if (!empty($a_title)) {
                $title_attr = $menu_text ? '' : 'title="' . $a_title . '"';
            } else {
                $title_attr = '';
            }
            if (isset($params['class'])) {
                //if set, use these classes instead of the default bootstrap
                $a_class = $params['class'];
            } else {
                $a_class = 'btn btn-link';
                //the default classes to be used
            }
            if (!empty($params['href'])) {
                //use href if not empty
                $a_href = 'href="' . $params['href'] . '"';
            } else {
                $a_href = '';
            }
            if (isset($params['data-toggle'])) {
                //add data-toggle if set
                $a_datatoggle = 'data-toggle="' . $params['data-toggle'] . '"';
            } else {
                $a_datatoggle = '';
            }
            if (isset($params['onclick'])) {
                //add onclick if set
                $a_onclick = 'onclick="' . $params['onclick'] . '"';
            } else {
                $a_onclick = '';
            }
            //assemble the link from the components
            if ($menu_text) {
                $icon = isset($params['_menu_icon']) && $params['_menu_icon'] === 'y' ? $html : '';
                $html = '<div class="iconmenu">' . $icon . '<span class="iconmenutext"> ' . $a_title . '</span></div>';
            } else {
                $html = "<a class='{$a_class}' {$title_attr} {$a_href} {$a_datatoggle} {$a_onclick}>{$html}</a>";
            }
        }
        //return the icon
        return $html;
    }
    //ICONSET END
    // Handle _ids that contains the real filename and path
    if (strpos($params['_id'], '/') !== false || strpos($params['_id'], '.') !== false) {
        if (($icons_basedir = dirname($params['_id'])) == '') {
            $icons_basedir = $basedirs[0];
        }
        $icons_basedir .= '/';
        if (($pos = strrpos($params['_id'], '.')) !== false) {
            $icons_extension = substr($params['_id'], $pos);
        }
        $params['_id'] = preg_replace('/^' . str_replace('/', '\\/', $icons_basedir) . '|' . $icons_extension . '$/', '', $params['_id']);
    } else {
        $icons_basedir = $basedirs[0] . '/';
    }
    if (!preg_match('/^[a-z0-9_-]+$/i', $params['_id'])) {
        return;
    }
    // Include smarty functions used below
    $smarty->loadPlugin('smarty_function_html_image');
    // auto-detect 'alt' param if not set
    if (!isset($params['alt'])) {
        $alt_pos = ($alt_pos = strrpos($params['_id'], '_')) === false ? 0 : $alt_pos + 1;
        $params['alt'] = tra(ucfirst(substr($params['_id'], $alt_pos)));
    }
    // handle special params and clean unrecognized params
    foreach ($params as $k => $v) {
        if ($k[0] == '_') {
            switch ($k) {
                case '_id':
                    $img_file = $v . $icons_extension;
                    $v = $icons_basedir . $img_file;
                    $themelib = TikiLib::lib('theme');
                    $v2 = $themelib->get_theme_path($current_theme, $current_theme_option, $img_file, 'icons/');
                    if (!empty($v2)) {
                        $params['file'] = $v2;
                    } else {
                        $params['file'] = $v;
                    }
                    break;
                case '_notag':
                    $notag = $v == 'y';
                    break;
                case '_menu_text':
                    $menu_text = $v == 'y';
                    $menu_icon = isset($params['_menu_icon']) && $params['_menu_icon'] == 'y';
                    break;
                case '_tag':
                    $tag = $v;
                    break;
                case '_confirm':
                    if ($prefs['javascript_enabled'] == 'y') {
                        $params['onclick'] = "return confirm('" . str_replace("'", "\\'", $v) . "');";
                    }
                    break;
            }
            unset($params[$k]);
        }
    }
    // default values for some params
    if (isset($params['path_prefix'])) {
        $params['basedir'] = $tikipath;
        $params['file'] = '/' . $params['file'];
    }
    if ($tag == 'img' && is_readable($params['file'])) {
        $dim = getimagesize($params['file']);
        if (!isset($params['width'])) {
            $params['width'] = $dim[0] ? $dim[0] : $default_width;
        }
        if (!isset($params['height'])) {
            $params['height'] = $dim[1] ? $dim[1] : $default_height;
        }
    }
    if ($notag) {
        $html = (isset($params['path_prefix']) ? $params['path_prefix'] : '') . $params['file'];
    } else {
        // use 'alt' as 'title' if not set
        if (!isset($params['title'])) {
            $params['title'] = $params['alt'];
        }
        // use default class if not set
        if (!isset($params['class'])) {
            $params['class'] = $default_class;
        }
        // remove empty arguments
        foreach ($params as $k => $v) {
            if ($v == '') {
                unset($params[$k]);
            }
        }
        // No need to add a title on a menu icon since there will be the same text just after the icon
        if ($menu_text) {
            $menu_text_val = $params['title'];
            unset($params['title']);
        }
        if ($tag != 'img') {
            $params['src'] = TikiLib::tikiUrlOpt($params['file']);
            unset($params['file']);
            foreach ($params as $k => $v) {
                $html .= ' ' . htmlspecialchars($k, ENT_QUOTES, 'UTF-8') . '="' . htmlspecialchars($v, ENT_QUOTES, 'UTF-8') . '"';
            }
        }
        if (!empty($params['file'])) {
            $headerlib = TikiLib::lib('header');
            $params['file'] = $headerlib->convert_cdn($params['file']);
            $params['file'] = TikiLib::tikiUrlOpt($params['file']);
        }
        switch ($tag) {
            case 'input_image':
                $html = '<input type="image"' . $html . ' />';
                break;
            case 'img':
            default:
                try {
                    $html = smarty_function_html_image($params, $smarty);
                } catch (Exception $e) {
                    $html = '<span class="icon error" title="' . tra('Error:') . ' ' . $e->getMessage() . '">?</span>';
                }
        }
        if ($tag != 'img') {
            // Add a span tag to be able to apply a CSS style on hover for the icon
            $html = "<span>{$html}</span>";
        }
        if ($menu_text) {
            if (!$menu_icon) {
                $html = '';
            }
            $html = '<div class="iconmenu">' . $html . '<span class="iconmenutext"> ' . $menu_text_val . '</span></div>';
        }
    }
    $cachelib->cacheItem($cache_key, $html);
    return $html;
}