예제 #1
0
function nvweb_breadcrumbs($vars = array())
{
    global $website;
    global $current;
    global $DB;
    global $structure;
    global $events;
    $out = '';
    if (empty($vars['separator'])) {
        $vars['separator'] = ' > ';
    }
    if ($vars['separator'] == 'image') {
        $vars['separator'] = '<img src="' . $vars['image'] . '" />';
    }
    if ($vars['separator'] == 'base64') {
        $vars['separator'] = base64_decode($vars['base64']);
    }
    if (empty($vars['from'])) {
        $vars['from'] = 0;
    }
    // 2 options: we are displaying an element or a category
    $breadcrumbs = array();
    if ($current['type'] == 'structure') {
        $breadcrumbs[] = $current['id'];
    } else {
        if ($current['type'] == 'item') {
            $breadcrumbs[] = $current['object']->category;
        }
    }
    if (!empty($breadcrumbs)) {
        // start looking for each category parent
        $parent = $breadcrumbs[0];
        while ($parent > 0) {
            $parent = nvweb_breadcrumbs_parent($parent);
            $breadcrumbs[] = $parent;
        }
        $vars['from'] = intval($vars['from']) + 1;
        nvweb_menu_load_dictionary();
        $breadcrumbs = array_reverse($breadcrumbs);
        $events->trigger('breadcrumbs', 'hierarchy', array('hierarchy' => &$breadcrumbs));
        for ($i = $vars['from']; $i < count($breadcrumbs); $i++) {
            if ($vars['links'] == 'false') {
                $out .= $structure['dictionary'][$breadcrumbs[$i]];
            } else {
                $out .= '<a ' . nvweb_menu_action($breadcrumbs[$i]) . '>' . $structure['dictionary'][$breadcrumbs[$i]] . '</a>';
            }
            if ($i + 1 < count($breadcrumbs)) {
                $out .= $vars['separator'];
            }
        }
    }
    return $out;
}
예제 #2
0
function nvweb_menu_action($id, $force_type = NULL, $use_javascript = true, $include_datasid = true)
{
    global $structure;
    global $current;
    $type = $structure['actions'][$id]['action-type'];
    if (!empty($force_type)) {
        $type = $force_type;
    }
    switch ($type) {
        case 'url':
            $url = $structure['routes'][$id];
            if (empty($url)) {
                if ($use_javascript) {
                    $url = 'javascript: return false;';
                } else {
                    $url = '#';
                }
            } else {
                $url = nvweb_prepare_link($url);
            }
            $action = ' href="' . $url . '" ';
            if ($include_datasid) {
                $action .= ' data-sid="' . $id . '" ';
            }
            break;
        case 'jump-branch':
            // we force only one jump to avoid infinite loops (caused by user mistake)
            $action = nvweb_menu_action($structure['actions'][$id]['action-jump-branch'], 'url');
            break;
        case 'jump-item':
            $url = nvweb_source_url('item', $structure['actions'][$id]['action-jump-item'], $current['lang']);
            if (empty($url)) {
                if ($use_javascript) {
                    $url = 'javascript: return false;';
                } else {
                    $url = '#';
                }
            } else {
                $url = nvweb_prepare_link($url);
            }
            $action = ' href="' . $url . '" ';
            if ($include_datasid) {
                $action .= ' data-sid="' . $id . '" ';
            }
            break;
        case 'do-nothing':
            $action = ' href="#" onclick="javascript: return false;" ';
            if ($include_datasid) {
                $action .= ' data-sid="' . $id . '" ';
            }
            break;
        default:
            // Navigate CMS < 1.6.5 compatibility [deprecated]
            // will be removed by 1.7
            $url = $structure['routes'][$id];
            if (substr($url, 0, 7) == 'http://' || substr($url, 0, 7) == 'https://') {
                $action = ' href="' . $url . '" target="_blank" ';
                if ($include_datasid) {
                    $action .= ' data-sid="' . $id . '" ';
                }
                return $action;
                // ;)
            } else {
                if (empty($url)) {
                    $action = ' href="#" onclick="return false;" ';
                    if ($include_datasid) {
                        $action .= ' data-sid="' . $id . '" ';
                    }
                    return $action;
                } else {
                    $action = ' href="' . NVWEB_ABSOLUTE . $url . '"';
                    if ($include_datasid) {
                        $action .= ' data-sid="' . $id . '" ';
                    }
                    return $action;
                }
            }
            break;
    }
    if ($structure['actions'][$id]['action-new-window'] == '1' && $type != 'do-nothing') {
        $action .= ' target="_blank"';
    }
    return $action;
}
예제 #3
0
function nvweb_content($vars = array())
{
    global $website;
    global $DB;
    global $current;
    global $template;
    global $structure;
    $out = '';
    switch (@$vars['mode']) {
        case 'title':
            if ($current['type'] == 'structure') {
                $rs = nvweb_content_items($current['object']->id, true, 1);
                $texts = webdictionary::load_element_strings('item', $rs[0]->id);
                $out = $texts[$current['lang']]['title'];
            } else {
                $texts = webdictionary::load_element_strings($current['type'], $current['object']->id);
                $out = $texts[$current['lang']]['title'];
            }
            if (!empty($vars['function'])) {
                eval('$out = ' . $vars['function'] . '("' . $out . '");');
            }
            break;
        case 'date':
        case 'date_post':
            $ts = $current['object']->date_to_display;
            // if no date, return nothing
            if (!empty($ts)) {
                $out = nvweb_content_date_format(@$vars['format'], $ts);
            }
            break;
        case 'date_created':
            $ts = $current['object']->date_created;
            $out = $vars['format'];
            $out = nvweb_content_date_format($out, $ts);
            break;
        case 'comments':
            // display published comments number for the current item
            $out = nvweb_content_comments_count();
            break;
        case 'views':
            $out = $current['object']->views;
            break;
        case 'summary':
            $length = 300;
            $allowed_tags = array();
            if (!empty($vars['length'])) {
                $length = intval($vars['length']);
            }
            $texts = webdictionary::load_element_strings('item', $current['object']->id);
            $text = $texts[$current['lang']]['main'];
            if (!empty($vars['allowed_tags'])) {
                $allowed_tags = explode(',', $vars['allowed_tags']);
            }
            $out = core_string_cut($text, 300, '&hellip;', $allowed_tags);
            break;
        case 'author':
            if (!empty($current['object']->author)) {
                $nu = new user();
                $nu->load($current['object']->author);
                $out = $nu->username;
                unset($nu);
            }
            if (empty($out)) {
                $out = $website->name;
            }
            break;
        case 'structure':
            // force loading structure data
            nvweb_menu();
            $structure_id = 0;
            if ($current['type'] == 'item') {
                $structure_id = $current['object']->category;
            } else {
                if ($current['type'] == 'structure') {
                    $structure_id = $current['object']->id;
                }
            }
            switch ($vars['return']) {
                case 'path':
                    $out = $structure['routes'][$structure_id];
                    break;
                case 'title':
                    $out = $structure['dictionary'][$structure_id];
                    break;
                case 'action':
                    $out = nvweb_menu_action($structure_id);
                    break;
                default:
            }
            break;
        case 'tags':
            $tags = array();
            $search_url = nvweb_source_url('theme', 'search');
            if (!empty($search_url)) {
                $search_url .= '?q=';
            } else {
                $search_url = NVWEB_ABSOLUTE . '/nvtags?q=';
            }
            $ids = array();
            if (empty($vars['separator'])) {
                $vars['separator'] = ' ';
            }
            $class = 'item-tag';
            if (!empty($vars['class'])) {
                $class = $vars['class'];
            }
            if (!empty($vars['id'])) {
                $itm = new item();
                $itm->load($vars['id']);
                $enabled = nvweb_object_enabled($itm);
                if ($enabled) {
                    $texts = webdictionary::load_element_strings('item', $itm->id);
                    $itags = explode(',', $texts[$current['lang']]['tags']);
                    if (!empty($itags)) {
                        for ($i = 0; $i < count($itags); $i++) {
                            if (empty($itags[$i])) {
                                continue;
                            }
                            $tags[$i] = '<a class="' . $class . '" href="' . $search_url . $itags[$i] . '">' . $itags[$i] . '</a>';
                        }
                    }
                }
            } else {
                if ($current['type'] == 'item') {
                    // check publishing is enabled
                    $enabled = nvweb_object_enabled($current['object']);
                    if ($enabled) {
                        $texts = webdictionary::load_element_strings('item', $current['object']->id);
                        $itags = explode(',', $texts[$current['lang']]['tags']);
                        if (!empty($itags)) {
                            for ($i = 0; $i < count($itags); $i++) {
                                if (empty($itags[$i])) {
                                    continue;
                                }
                                $tags[$i] = '<a class="' . $class . '" href="' . $search_url . $itags[$i] . '">' . $itags[$i] . '</a>';
                            }
                        }
                    }
                } else {
                    if ($current['type'] == 'structure') {
                        $rs = nvweb_content_items($current['object']->id);
                        foreach ($rs as $category_item) {
                            $enabled = nvweb_object_enabled($category_item);
                            if ($enabled) {
                                $texts = webdictionary::load_element_strings('item', $current['object']->id);
                                $itags = explode(',', $texts[$current['lang']]['tags']);
                                if (!empty($itags)) {
                                    for ($i = 0; $i < count($itags); $i++) {
                                        $tags[$i] = '<a class="' . $class . '" href="' . $search_url . $itags[$i] . '">' . $itags[$i] . '</a>';
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $out = implode($vars['separator'], $tags);
            break;
        case 'section':
        case 'body':
        default:
            if (empty($vars['section'])) {
                $vars['section'] = 'main';
            }
            $section = "section-" . $vars['section'];
            if ($current['type'] == 'item') {
                // check publishing is enabled
                $enabled = nvweb_object_enabled($current['object']);
                $texts = NULL;
                // retrieve last saved text (is a preview request from navigate)
                if ($_REQUEST['preview'] == 'true' && $current['navigate_session'] == 1) {
                    $texts = webdictionary_history::load_element_strings('item', $current['object']->id, 'latest');
                } else {
                    if ($enabled) {
                        $texts = webdictionary::load_element_strings('item', $current['object']->id);
                    }
                }
                // have we found any content?
                if (!empty($texts)) {
                    foreach ($template->sections as $tsection) {
                        if ($tsection['id'] == $vars['section'] || $tsection['code'] == $vars['section']) {
                            switch ($tsection['editor']) {
                                case 'raw':
                                    $out = nl2br($texts[$current['lang']][$section]);
                                    break;
                                case 'html':
                                case 'tinymce':
                                default:
                                    $out = $texts[$current['lang']][$section];
                                    break;
                            }
                            break;
                        }
                    }
                }
            } else {
                if ($current['type'] == 'structure') {
                    $rs = nvweb_content_items($current['object']->id);
                    foreach ($rs as $category_item) {
                        $enabled = nvweb_object_enabled($category_item);
                        if (!$enabled) {
                            continue;
                        } else {
                            $texts = webdictionary::load_element_strings('item', $category_item->id);
                            foreach ($template->sections as $tsection) {
                                if ($tsection['id'] == $vars['section'] || $tsection['code'] == $vars['section']) {
                                    switch ($tsection['editor']) {
                                        case 'raw':
                                            $texts[$current['lang']][$section] = nl2br($texts[$current['lang']][$section]);
                                            break;
                                        case 'html':
                                        case 'tinymce':
                                        default:
                                            // we don't need to change a thing
                                            // $texts[$current['lang']][$section] = $texts[$current['lang']][$section];
                                            break;
                                    }
                                    break;
                                }
                            }
                            $out .= '<div id="navigate-content-' . $category_item->id . '-' . $section . '">' . $texts[$current['lang']][$section] . '</div>';
                        }
                    }
                }
            }
            break;
    }
    return $out;
}