Example #1
0
function nvweb_blocks($vars = array())
{
    global $website;
    global $DB;
    global $current;
    global $webgets;
    global $webuser;
    global $theme;
    $webget = 'blocks';
    nvweb_blocks_init();
    $out = '';
    $access = array();
    $access[] = 0;
    if (empty($current['webuser'])) {
        // 1: only signed in users, 2: only NON signed in users, 3: selected web user groups only
        $access[] = 2;
    } else {
        $access[] = 1;
        $access[] = 3;
    }
    // blocks type cache
    if (empty($webgets[$webget]['block_types'])) {
        $webgets[$webget]['block_types'] = block::types();
    }
    $block_types = $webgets[$webget]['block_types'];
    if ($vars['mode'] == 'single') {
        $order_mode = 'single';
    } else {
        // get the index for the block type requested
        $bti = array_multidimensional_search($block_types, array('code' => $vars['type']));
        // how must we process this block type
        $order_mode = @$block_types[$bti]['order'];
        if (empty($order_mode) || $order_mode == 'theme') {
            $order_mode = @$vars['mode'];
        }
    }
    // how many blocks of this type we have to show
    $howmany = @intval($block_types[$bti]['maximum']);
    if (empty($howmany) || $howmany > intval(@$vars['number']) && !empty($vars['number'])) {
        $howmany = intval(@$vars['number']) + 0;
    }
    // which zone of the block we have to return
    if (empty($vars['zone'])) {
        $vars['zone'] = 'block';
    }
    $categories = array();
    if (!empty($vars['categories'])) {
        $categories = explode(',', $vars['categories']);
        $categories = array_filter($categories);
    }
    if (isset($current['object']->category)) {
        $categories[] = $current['object']->category;
    } else {
        $categories[] = $current['category'];
    }
    $blocks = array();
    $categories_query = '';
    $exclusions_query = '';
    if (is_array($categories) && !empty($categories[0])) {
        foreach ($categories as $cq) {
            $categories_query .= " OR INSTR(CONCAT(',', categories, ','), '," . intval($cq) . ",') > 0 ";
            $exclusions_query .= " AND INSTR(CONCAT(',', exclusions, ','), '," . intval($cq) . ",') = 0 ";
        }
        $categories_query = ' AND (categories = "" ' . $categories_query . ') ';
    }
    switch ($order_mode) {
        case 'single':
            $query_type = '';
            if (!empty($vars['type'])) {
                $query_type = ' AND type = ' . protect($vars['type']);
            }
            $DB->query('
                SELECT id, type
                  FROM nv_blocks
                 WHERE enabled = 1
                   ' . $query_type . '
                   AND website = ' . $website->id . '
                   AND (date_published = 0 OR date_published < ' . core_time() . ')
                   AND (date_unpublish = 0 OR date_unpublish > ' . core_time() . ')
                   AND access IN(' . implode(',', $access) . ')
                   ' . $categories_query . '
                   ' . $exclusions_query . '
                   AND id = ' . protect($vars['id']));
            $row = $DB->first();
            if (!empty($row)) {
                $blocks[] = $row->id;
                $vars['type'] = $row->type;
            }
            break;
        case 'priority':
        case 'ordered':
            $DB->query('
                SELECT *
                  FROM nv_blocks
                 WHERE type = ' . protect($vars['type']) . '
                   AND enabled = 1
                   AND website = ' . $website->id . '
                   AND (date_published = 0 OR date_published < ' . core_time() . ')
                   AND (date_unpublish = 0 OR date_unpublish > ' . core_time() . ')
                   AND access IN(' . implode(',', $access) . ')
                   ' . $categories_query . '
                   ' . $exclusions_query . '
                ORDER BY position ASC
            ');
            $rows = $DB->result();
            foreach ($rows as $row) {
                if (!nvweb_block_enabled($row)) {
                    continue;
                }
                $row = (array) $row;
                $blocks[] = $row['id'];
            }
            break;
        default:
        case 'random':
            // "random" gets priority blocks first
            // retrieve fixed blocks
            $DB->query('
                SELECT *
                  FROM nv_blocks
                 WHERE type = ' . protect($vars['type']) . '
                   AND enabled = 1
                   AND website = ' . $website->id . '
                   AND (date_published = 0 OR date_published < ' . core_time() . ')
                   AND (date_unpublish = 0 OR date_unpublish > ' . core_time() . ')
                   AND access IN(' . implode(',', $access) . ')
                   AND fixed = 1
                   ' . $categories_query . '
                   ' . $exclusions_query . '
              ORDER BY position ASC
            ');
            $fixed_rows = $DB->result();
            $fixed_rows_ids = $DB->result('id');
            if (empty($fixed_rows_ids)) {
                $fixed_rows_ids = array(0);
            }
            // now retrieve the other blocks in random order
            $DB->query('
			    SELECT *
                  FROM nv_blocks
                 WHERE type = ' . protect($vars['type']) . '
                   AND enabled = 1
                   AND website = ' . $website->id . '
                   AND (date_published = 0 OR date_published < ' . core_time() . ')
                   AND (date_unpublish = 0 OR date_unpublish > ' . core_time() . ')
                   AND access IN(' . implode(',', $access) . ')
                   AND id NOT IN(' . implode(",", $fixed_rows_ids) . ')
                   ' . $categories_query . '
                   ' . $exclusions_query . '
                 ORDER BY RAND()
            ');
            $random_rows = $DB->result();
            // mix rows (fixed and random)
            // fixed position rows
            foreach ($fixed_rows as $fr) {
                if (!nvweb_block_enabled($fr)) {
                    continue;
                }
                $blocks[$fr->position] = $fr->id;
            }
            // random position rows
            $pos = 0;
            foreach ($random_rows as $rr) {
                if (!nvweb_block_enabled($rr)) {
                    continue;
                }
                // find next free position
                $free = false;
                while (!$free) {
                    $free = empty($blocks[$pos]);
                    if (!$free) {
                        $pos++;
                    }
                }
                $blocks[$pos] = $rr->id;
            }
            // sort array by key
            ksort($blocks);
            break;
    }
    // render the blocks found
    $shown = 0;
    $position = 1;
    $block_objects = array();
    foreach ($blocks as $id) {
        if ($howmany > 0 && $shown >= $howmany) {
            break;
        }
        $block = new block();
        $block->load($id);
        $bt = 'block';
        for ($bti = 0; $bti < count($block_types); $bti++) {
            if ($block->type == $block_types[$bti]['code']) {
                $bt = $block_types[$bti]['type'];
                break;
            }
        }
        // SKIP all blocks until a certain position
        if (isset($vars['position']) && $vars['position'] != $position) {
            $position++;
            continue;
        }
        // RENDER block zone
        switch ($vars['zone']) {
            case 'object':
                $block_objects[] = clone $block;
                break;
            case 'title':
                $out .= '<span class="block-' . $vars['type'] . '-title" zone="title" ng-block-id="' . $block->id . '">' . $block->dictionary[$current['lang']]['title'] . '</span>';
                break;
            case 'content':
            case 'block':
            default:
                if ($bt == 'theme') {
                    $fn = 'nvweb_' . $website->theme . '_blocks_render';
                    $out .= '<div class="block-' . $vars['type'] . '" ng-block-id="' . $block->id . '">';
                    $out .= $fn($block, $vars);
                    $out .= '</div>' . "\n";
                } else {
                    $out .= '<div class="block-' . $vars['type'] . '" ng-block-id="' . $block->id . '">';
                    $out .= nvweb_blocks_render($vars['type'], $block->trigger, $block->action, $vars['zone'], $block, $vars);
                    $out .= '</div>' . "\n";
                }
                break;
        }
        // the block requested at a CERTAIN POSITION was this, we've finished
        if (isset($vars['position']) && $vars['position'] == $position) {
            break;
        }
        $shown++;
        $position++;
    }
    if ($vars['zone'] == 'object') {
        $out = array($block_objects, count($block_objects));
    }
    return $out;
}
Example #2
0
function nvweb_list_parse_tag($tag, $item, $source = 'item', $item_relative_position, $item_absolute_position, $total)
{
    global $current;
    global $website;
    global $structure;
    global $DB;
    $out = '';
    switch ($tag['attributes']['source']) {
        // special condition, return direct query result values
        case 'query':
            $out = $item->_query->{$tag}['attributes']['value'];
            break;
            // special: return element position in list
        // special: return element position in list
        case 'position':
            $position = $item_relative_position;
            if ($tag['attributes']['absolute'] == 'true') {
                $position = $item_absolute_position;
            }
            switch ($tag['attributes']['type']) {
                case 'alphabetic':
                    $out = number2alphabet($position);
                    break;
                case 'numeric':
                default:
                    $out = $position + 1;
                    // first element is 1, but in list is zero
                    break;
            }
            break;
            // NOTE: the following refers to structure information of an ITEM, useless if the source are categories!
        // NOTE: the following refers to structure information of an ITEM, useless if the source are categories!
        case 'structure':
        case 'category':
            nvweb_menu_load_dictionary();
            // load menu translations if not already done
            nvweb_menu_load_routes();
            // load menu paths if not already done
            switch ($tag['attributes']['value']) {
                case 'title':
                    if ($source == 'structure' || $source == 'category') {
                        $out = $structure['dictionary'][$item->id];
                    } else {
                        $out = $structure['dictionary'][$item->category];
                    }
                    if (!empty($tag['attributes']['length'])) {
                        $out = core_string_cut($out, $tag['attributes']['length'], '&hellip;');
                    }
                    break;
                case 'slug':
                    if ($source == 'structure' || $source == 'category') {
                        $out = $structure['dictionary'][$item->id];
                    } else {
                        $out = $structure['dictionary'][$item->category];
                    }
                    // remove spaces, special chars, etc.
                    $out = core_string_clean($out);
                    $out = slug($out);
                    break;
                case 'property':
                    $id = $item->id;
                    if ($source != 'structure' && $source != 'category') {
                        $id = $item->category;
                    }
                    $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => !isset($tag['attributes']['mode']) ? 'structure' : $tag['attributes']['mode'], 'id' => $id, 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name']));
                    $out = nvweb_properties($nvweb_properties_parameters);
                    break;
                case 'url':
                case 'path':
                    if ($source == 'structure' || $source == 'category') {
                        $out = $structure['routes'][$item->id];
                    } else {
                        $out = $structure['routes'][$item->category];
                    }
                    $out = nvweb_prepare_link($out);
                    break;
                case 'id':
                    if ($source == 'structure' || $source == 'category') {
                        $out = $item->id;
                    } else {
                        // source = 'item'?
                        $out = $item->category;
                    }
                    break;
                default:
                    break;
            }
            break;
            // ITEM comments
        // ITEM comments
        case 'comment':
        case 'comments':
            switch ($tag['attributes']['value']) {
                case 'id':
                    $out = $item->id;
                    break;
                case 'avatar':
                    $size = '48';
                    $extra = '';
                    if (!empty($tag['attributes']['size'])) {
                        $size = intval($tag['attributes']['size']);
                    }
                    if (!empty($tag['attributes']['border'])) {
                        $extra .= '&border=' . $tag['attributes']['border'];
                    }
                    if (!empty($item->avatar)) {
                        $out = '<img class="' . $tag['attributes']['class'] . '" src="' . NVWEB_OBJECT . '?type=image' . $extra . '&id=' . $item->avatar . '" width="' . $size . 'px" height="' . $size . 'px"/>';
                    } else {
                        if (!empty($tag['attributes']['default'])) {
                            // the comment creator has not an avatar, but the template wants to show a default one
                            // 3 cases:
                            //  numerical   ->  ID of the avatar image file in Navigate CMS
                            //  absolute path (http://www...)
                            //  relative path (/img/avatar.png) -> path to the avatar file included in the THEME used
                            if (is_numeric($tag['attributes']['default'])) {
                                $out = '<img class="' . $tag['attributes']['class'] . '" src="' . NVWEB_OBJECT . '?type=image' . $extra . '&id=' . $tag['attributes']['default'] . '" width="' . $size . 'px" height="' . $size . 'px"/>';
                            } else {
                                if (strpos($tag['attributes']['default'], 'http://') === 0) {
                                    $out = '<img class="' . $tag['attributes']['class'] . '" src="' . $tag['attributes']['default'] . '" width="' . $size . 'px" height="' . $size . 'px"/>';
                                } else {
                                    if ($tag['attributes']['default'] == 'none') {
                                        $out = '';
                                    } else {
                                        $out = '<img class="' . $tag['attributes']['class'] . '"src="' . NAVIGATE_URL . '/themes/' . $website->theme . '/' . $tag['attributes']['default'] . '" width="' . $size . 'px" height="' . $size . 'px"/>';
                                    }
                                }
                            }
                        } else {
                            $gravatar_hash = "";
                            $gravatar_default = 'blank';
                            if (!empty($tag['attributes']['gravatar_default'])) {
                                $gravatar_default = $tag['attributes']['gravatar_default'];
                            }
                            if (!empty($item->email)) {
                                $gravatar_hash = md5(strtolower(trim($item->email)));
                            } else {
                                if (!empty($item->user)) {
                                    $email = $DB->query_single('email', 'nv_webusers', 'id = ' . protect($item->user));
                                    if (!empty($email)) {
                                        $gravatar_hash = md5(strtolower(trim($item->email)));
                                    }
                                }
                            }
                            if (!empty($gravatar_hash) && $gravatar_default != 'none') {
                                // gravatar real url: https://www.gravatar.com/avatar/
                                // we use libravatar to get more userbase
                                $gravatar_url = 'https://seccdn.libravatar.org/avatar/' . $gravatar_hash . '?s=' . $size . '&d=' . $gravatar_default;
                                $out = '<img class="' . $tag['attributes']['class'] . '" src="' . $gravatar_url . '" width="' . $size . 'px" height="' . $size . 'px"/>';
                            } else {
                                $out = '<img class="' . $tag['attributes']['class'] . '" src="data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="' . $size . 'px" height="' . $size . 'px"/>';
                            }
                        }
                    }
                    if ($tag['attributes']['linked'] == 'true' && !empty($out)) {
                        if (!empty($item->url)) {
                            $comment_link = $item->url;
                        } else {
                            if (!empty($item->user)) {
                                $wu = new webuser();
                                $wu->load($item->user);
                                $comment_link = $wu->social_website;
                            }
                        }
                        if (!empty($comment_link)) {
                            $out = '<a href="' . $comment_link . '" target="_blank">' . $out . '</a>';
                        }
                    }
                    break;
                case 'username':
                    $out = !empty($item->username) ? $item->username : $item->name;
                    if ($tag['attributes']['linked'] == 'true' && !empty($out)) {
                        if (!empty($item->url)) {
                            $comment_link = $item->url;
                        } else {
                            if (!empty($item->user)) {
                                $wu = new webuser();
                                $wu->load($item->user);
                                $comment_link = $wu->social_website;
                            }
                        }
                        if (!empty($comment_link)) {
                            $out = '<a href="' . $comment_link . '" target="_blank">' . $out . '</a>';
                        }
                    }
                    break;
                case 'website':
                    if (!empty($item->url)) {
                        $out = $item->url;
                    } else {
                        if (!empty($item->user)) {
                            $wu = new webuser();
                            $wu->load($item->user);
                            $out = $wu->social_website;
                        }
                    }
                    if (empty($out)) {
                        $out = '#';
                    }
                    break;
                case 'message':
                    if (!empty($tag['attributes']['length'])) {
                        $out = core_string_cut($item->message, $tag['attributes']['length'], '&hellip;');
                    } else {
                        $out = nl2br($item->message);
                    }
                    break;
                case 'date':
                    // Navigate CMS 1.6.6 compatibility
                    if (empty($tag['attributes']['format']) && !empty($tag['attributes']['date_format'])) {
                        $tag['attributes']['format'] = $tag['attributes']['date_format'];
                    }
                    if (!empty($tag['attributes']['format'])) {
                        // custom date format
                        $out = nvweb_content_date_format($tag['attributes']['format'], $item->date_created);
                    } else {
                        $out = date($website->date_format . ' H:i', $item->date_created);
                    }
                    break;
                case 'item_url':
                    $out = nvweb_source_url('item', $item->item, $current['lang']);
                    break;
                case 'item_title':
                    $out = $item->item_title;
                    break;
                case 'reply_to':
                    $out = $item->reply_to;
                    break;
                case 'depth':
                    $c = new comment();
                    $c->load_from_resultset(array($item));
                    $out = $c->depth();
                    break;
                case 'property':
                    $c = new comment();
                    $c->load_from_resultset(array($item));
                    // pass all nvlist tag parameters to properties nvweb, but some attribute/values take preference
                    $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => 'comment', 'id' => $c->id, 'template' => $c->element_template(), 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name']));
                    $out = nvweb_properties($nvweb_properties_parameters);
                    break;
            }
            break;
        case 'block':
            switch ($tag['attributes']['value']) {
                case 'id':
                    $out = $item->id;
                    break;
                    // only for blocks in a block group!
                // only for blocks in a block group!
                case 'uid':
                    $out = $item->uid;
                    break;
                case 'block':
                    // generate the full block code
                    if ($item->type == "extension") {
                        if (function_exists('nvweb_' . $item->extension . '_' . $item->id)) {
                            // load extension block property values
                            $item->properties = property::load_properties(NULL, $item->id, "extension_block", NULL, $item->uid);
                            $out = call_user_func('nvweb_' . $item->extension . '_' . $item->id, $item);
                        }
                    } else {
                        $out = nvweb_blocks_render($item->type, $item->trigger, $item->action, NULL, NULL, $tag['attributes']);
                    }
                    break;
                    // not for extension_blocks
                // not for extension_blocks
                case 'title':
                    $out = $item->dictionary[$current['lang']]['title'];
                    if (!empty($tag['attributes']['length'])) {
                        $out = core_string_cut($out, $tag['attributes']['length'], '&hellip;');
                    }
                    break;
                case 'content':
                    if ($item->type == "extension") {
                        if (function_exists('nvweb_' . $item->extension . '_' . $item->id)) {
                            // load extension block property values
                            $item->properties = property::load_properties(NULL, $item->id, "extension_block", NULL, $item->uid);
                            $out = call_user_func('nvweb_' . $item->extension . '_' . $item->id, $item);
                        }
                    } else {
                        $out = nvweb_blocks_render($item->type, $item->trigger, $item->action, 'content', $item, $tag['attributes']);
                    }
                    break;
                    // not for extension_blocks
                // not for extension_blocks
                case 'url':
                case 'path':
                    $out = nvweb_blocks_render_action($item->action, '', $current['lang'], true);
                    if (empty($out)) {
                        $out = '#';
                    } else {
                        $out = nvweb_prepare_link($out);
                    }
                    break;
                    // not for extension_blocks
                // not for extension_blocks
                case 'target':
                    if ($item->action['action-type'][$current['lang']] == 'web-n') {
                        $out = '_blank';
                    } else {
                        $out = '_self';
                    }
                    break;
                    // not for extension_blocks (only for standard blocks and block group blocks)
                // not for extension_blocks (only for standard blocks and block group blocks)
                case 'property':
                    $properties_mode = 'block';
                    if (!is_numeric($item->id)) {
                        $properties_mode = 'block_group_block';
                    }
                    $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => !isset($tag['attributes']['mode']) ? $properties_mode : $tag['attributes']['mode'], 'id' => $item->id, 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name'], 'uid' => @$item->uid));
                    $out = nvweb_properties($nvweb_properties_parameters);
                    break;
                    // not for extension_blocks
                // not for extension_blocks
                case 'poll_answers':
                    $out = nvweb_blocks_render_poll($item);
                    break;
                default:
                    break;
            }
            break;
        case 'block_link':
            switch ($tag['attributes']['value']) {
                case 'id':
                    $out = $item->id;
                    break;
                case 'title':
                    $out = $item->title;
                    if (!empty($tag['attributes']['length'])) {
                        $out = core_string_cut($out, $tag['attributes']['length'], '&hellip;');
                    }
                    break;
                case 'url':
                case 'path':
                    $out = $item->link;
                    if (empty($out)) {
                        $out = '#';
                    } else {
                        $out = nvweb_prepare_link($out);
                    }
                    break;
                case 'target':
                    if ($item->new_window == 1) {
                        $out = '_blank';
                    } else {
                        $out = '_self';
                    }
                    break;
                case 'icon':
                    $out = @$item->icon;
                    break;
                default:
                    break;
            }
            break;
        case 'block_type':
            switch ($tag['attributes']['value']) {
                case 'title':
                    $title_obj = json_decode($item->title, true);
                    if (empty($title_obj)) {
                        // not json
                        $out = $item->title;
                    } else {
                        $out = $title_obj[$current['lang']];
                    }
                    break;
            }
            break;
        case 'gallery':
            switch ($tag['attributes']['value']) {
                case 'url':
                case 'path':
                    $out = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&amp;disposition=inline';
                    break;
                case 'thumbnail':
                case 'thumbnail_url':
                    $thumbnail_url = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&amp;disposition=inline&amp;width=' . $tag['attributes']['width'] . '&amp;height=' . $tag['attributes']['height'] . '&amp;border=' . $tag['attributes']['border'];
                    if ($tag['attributes']['value'] == 'thumbnail_url' || @$tag['attributes']['return'] == 'url') {
                        $out = $thumbnail_url;
                    } else {
                        $out = '<img src="' . $thumbnail_url . '" alt="' . $item[$current['lang']] . '" title="' . $item[$current['lang']] . '" />';
                    }
                    break;
                case 'title':
                    $f = new file();
                    $f->load($item['file']);
                    $out = $f->title[$current['lang']];
                    break;
                case 'alt':
                case 'description':
                    $f = new file();
                    $f->load($item['file']);
                    $out = $f->description[$current['lang']];
                    break;
                default:
                    $out = '<a href="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&amp;disposition=inline">
                                <img src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&amp;disposition=inline&amp;width=' . $tag['attributes']['width'] . '&amp;height=' . $tag['attributes']['height'] . '&amp;border=' . $tag['attributes']['border'] . '"
									 alt="' . $item[$current['lang']] . '" title="' . $item[$current['lang']] . '" />
                            </a>';
                    break;
            }
            break;
        case 'item':
            // useful also for source="structure" (but some are nonsense: title, comments, etc)
        // useful also for source="structure" (but some are nonsense: title, comments, etc)
        default:
            switch ($tag['attributes']['value']) {
                case 'id':
                    $out = $item->id;
                    break;
                case 'slug':
                    $lang = $current['lang'];
                    if (!empty($tag['attributes']['lang'])) {
                        $lang = $tag['attributes']['lang'];
                    }
                    $out = $item->dictionary[$lang]['title'];
                    // remove spaces, special chars, etc.
                    $out = core_string_clean($out);
                    $out = slug($out);
                    break;
                case 'title':
                    $lang = $current['lang'];
                    if (!empty($tag['attributes']['lang'])) {
                        $lang = $tag['attributes']['lang'];
                    }
                    $out = $item->dictionary[$lang]['title'];
                    if (!empty($tag['attributes']['length'])) {
                        $out = core_string_cut($out, $tag['attributes']['length'], '&hellip;', $tag['attributes']['length']);
                    }
                    break;
                case 'author':
                    if (!empty($item->author)) {
                        $nu = new user();
                        $nu->load($item->author);
                        $out = $nu->username;
                        unset($nu);
                    }
                    if (empty($out)) {
                        $out = $website->name;
                    }
                    break;
                case 'date':
                case 'date_post':
                    if (!empty($tag['attributes']['format'])) {
                        // custom date format
                        $out = nvweb_content_date_format($tag['attributes']['format'], $item->date_to_display);
                    } else {
                        $out = date($website->date_format, $item->date_to_display);
                    }
                    break;
                case 'content':
                case 'section':
                    if ($source == 'structure' && $tag['attributes']['source'] == 'item') {
                        $items = nvweb_content_items($item->id, true, 1, false, 'priority');
                        // we force finding the first non-embedded item ordered by priority
                        if (empty($items)) {
                            $items = nvweb_content_items($item->id, true, 1, true, 'priority');
                        }
                        // find the first embedded item ordered by priority
                        $item = $items[0];
                    }
                    $section = $tag['attributes']['section'];
                    if (empty($section)) {
                        $section = 'main';
                    }
                    $out = $item->dictionary[$current['lang']]['section-' . $section];
                    if (!empty($tag['attributes']['length'])) {
                        $allowed_tags = '';
                        if (!empty($tag['attributes']['allowed_tags'])) {
                            $allowed_tags = explode(',', $tag['attributes']['allowed_tags']);
                        }
                        $out = core_string_cut($out, $tag['attributes']['length'], '&hellip;', $allowed_tags);
                    }
                    break;
                case 'comments':
                    $out = nvweb_content_comments_count($item->id);
                    break;
                case 'gallery':
                    $params = array('item' => $item->id);
                    $params = array_merge($params, $tag['attributes']);
                    $out = nvweb_gallery($params);
                    break;
                case 'image':
                case 'photo':
                    $photo = @array_shift(array_keys($item->galleries[0]));
                    if (empty($photo)) {
                        $out = NVWEB_OBJECT . '?type=transparent';
                    } else {
                        $out = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $photo . '&amp;disposition=inline&amp;width=' . $tag['attributes']['width'] . '&amp;height=' . $tag['attributes']['height'] . '&amp;border=' . $tag['attributes']['border'];
                    }
                    break;
                case 'url':
                case 'path':
                    // rss -> full url
                    // item -> relative url
                    // embedded item -> category url
                    if ($item->embedding == 1 && $item->association == 'category') {
                        nvweb_menu_load_routes();
                        // load menu paths if not already done
                        $out = nvweb_prepare_link($structure['routes'][$item->category]);
                    } else {
                        $path = $item->paths[$current['lang']];
                        if (empty($path)) {
                            $path = '/node/' . $item->id;
                        }
                        $out = nvweb_prepare_link($path);
                    }
                    break;
                case 'tags':
                    // pass all nvlist tag parameters to the content nvweb, but some attribute/values take preference
                    $nvweb_parameters = array_replace($tag['attributes'], array('mode' => 'tags', 'id' => $item->id));
                    $out = nvweb_content($nvweb_parameters);
                    break;
                case 'score':
                    $out = nvweb_votes_calc($item, $tag['attributes']['round'], $tag['attributes']['half'], $tag['attributes']['min'], $tag['attributes']['max']);
                    break;
                case 'votes':
                    $out = intval($item->votes);
                    break;
                case 'views':
                    $out = intval($item->views);
                    break;
                case 'property':
                    if ($source == 'structure' && $tag['attributes']['source'] == 'item') {
                        $items = nvweb_content_items($item->id, true, 1, false, 'priority');
                        // we force finding the first non-embedded item ordered by priority
                        if (empty($items)) {
                            $items = nvweb_content_items($item->id, true, 1, true, 'priority');
                        }
                        // find the first embedded item ordered by priority
                        $item = $items[0];
                        $source = "item";
                    }
                    // pass all nvlist tag parameters to properties nvweb, but some attribute/values take preference
                    $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => $source == 'structure' || $source == 'category' ? 'structure' : 'item', 'id' => $item->id, 'template' => $item->template, 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name']));
                    $out = nvweb_properties($nvweb_properties_parameters);
                    break;
                default:
                    // maybe a special tag not related to a source? (unimplemented)
            }
            break;
    }
    return $out;
}