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; }
function nvweb_menu($vars = array()) { global $website; global $DB; global $structure; global $current; $out = ''; nvweb_menu_load_dictionary(); nvweb_menu_load_routes(); nvweb_menu_load_structure(); nvweb_menu_load_actions(); $parent = intval(@$vars['parent']) + 0; $from = intval(@$vars['from']) + 0; $of = intval(@$vars['of']) + 0; if (isset($vars['parent']) && !is_numeric($vars['parent'])) { // assume parent attribute contains a property_id which has the category value $parent_property = nvweb_properties(array('property' => $vars['parent'])); if (!empty($parent_property)) { $parent = $parent_property; } } if ($of > 0) { // get options of the parent x in the order of the structure // example: // Home [5] Products [6] Contact [7] // | // -- Computers [8] Mobile Phones [9] // | // -- Apple [10] Dell [11] // // we want the categories under Products [6]: "Computers" [8] and "Mobile Phones" [9] // of: 2 (second item in the main structure) // <nv object="nvweb" name="menu" of="2" /> $parent = $structure['cat-0'][intval($of) - 1]->id; } if (empty($current['hierarchy'])) { $inverse_hierarchy = array(); // discover the parent from which get the menu if (!empty($current['category'])) { $inverse_hierarchy[] = $current['category']; $last = $current['category']; } else { $inverse_hierarchy[] = $current['object']->category; $last = $current['object']->category; } // get category parents until root (to know how many levels count from) while ($last > 0) { $last = $DB->query_single('parent', 'nv_structure', ' id = ' . protect($last)); $inverse_hierarchy[] = $last; } $current['hierarchy'] = array_reverse($inverse_hierarchy); } if ($from > 0) { // get a certain level of the menu based on the path to current item category with offset // example: // Home [5] Products [6] Contact [7] // | // -- Computers [8] Mobile Phones [9] // | // -- Apple [10] Dell [11] // // current item is a Dell computer (category = 11) // we want the menu from level 1 // from: 1 --> 8, 9 $parent = $current['hierarchy'][$from]; if (is_null($parent)) { return ''; } // the requested level of menu does not exist under the current category } $option = -1; if (isset($vars['option'])) { $option = intval($vars['option']); } if ($vars['mode'] == 'next' || $vars['mode'] == 'previous') { $out = nvweb_menu_render_arrow($vars); } else { $out = nvweb_menu_generate($vars['mode'], $vars['levels'], $parent, 0, $option, $vars['class']); if ($vars['mode'] == 'select') { nvweb_after_body('js', ' // jQuery required $("select.menu_level_0").off("change").on("change", function() { var option = $(this).find("option[value=" + $(this).val() + "]"); if($(option).attr("target") == "_blank") window.open($(option).attr("href")); else { if($(option).attr("href")=="#") window.location.replace($(option).attr("href") + "sid_" + $(option).attr("value")); else window.location.replace($(option).attr("href")); } }); '); } } return $out; }
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'], '…'); } 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'], '…'); } 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'], '…'); } 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'], '…'); } 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'] . '&disposition=inline'; break; case 'thumbnail': case 'thumbnail_url': $thumbnail_url = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&disposition=inline&width=' . $tag['attributes']['width'] . '&height=' . $tag['attributes']['height'] . '&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'] . '&disposition=inline"> <img src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&disposition=inline&width=' . $tag['attributes']['width'] . '&height=' . $tag['attributes']['height'] . '&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'], '…', $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'], '…', $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 . '&disposition=inline&width=' . $tag['attributes']['width'] . '&height=' . $tag['attributes']['height'] . '&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; }
/** * Parses a template looking for nv tags and replacing them with the generated HTML code * * @param $template string HTML code to parse * @return string HTML page generated */ function nvweb_template_parse($template) { global $dictionary; global $DB; global $current; global $website; global $structure; global $theme; global $idn; global $session; $html = $template; // now parse autoclosing tags $tags = nvweb_tags_extract($html, 'nv', true, true, 'UTF-8'); foreach ($tags as $tag) { $content = ''; switch ($tag['attributes']['object']) { // MAIN OBJECT TYPES case 'nvweb': case 'widget': case 'webget': case '': // webgets on lib/webgets have priority over private/webgets nvweb_webget_load($tag['attributes']['name']); $fname = 'nvweb_' . $tag['attributes']['name']; $tag['attributes']['nvweb_html'] = $html; // always pass the current buffered output to the webget if (function_exists($fname)) { $content = $fname($tag['attributes']); } break; case 'root': $content = NVWEB_ABSOLUTE; break; case 'nvajax': $content = NVWEB_AJAX; break; case 'url': $content = ''; if (!empty($tag['attributes']['lang'])) { $lang = $tag['attributes']['lang']; } else { $lang = $current['lang']; } if (!empty($tag['attributes']['type']) && !empty($tag['attributes']['id'])) { $url = nvweb_source_url($tag['attributes']['type'], $tag['attributes']['id'], $lang); if (!empty($url)) { $content .= $url; } } else { if (!empty($tag['attributes']['type']) && !empty($tag['attributes']['property'])) { $tag['attributes']['id'] = nvweb_properties(array('property' => $tag['attributes']['property'])); $url = nvweb_source_url($tag['attributes']['type'], $tag['attributes']['id'], $lang); if (!empty($url)) { $content .= $url; } } else { if (!empty($tag['attributes']['type']) && empty($tag['attributes']['id'])) { // get structure parent for this element and return its path if ($current['type'] == 'structure') { $category = $current['object']->parent; if (empty($category)) { $category = $current['object']->id; } } else { $category = $current['object']->category; } $url = nvweb_source_url($tag['attributes']['type'], $category, $lang); if (!empty($url)) { $content .= $url; } } else { $content .= '/' . $current['route']; } } } $content = nvweb_prepare_link($content); break; case 'd': case 'dict': case 'dictionary': if (!empty($tag['attributes']['type'])) { if ($tag['attributes']['type'] == 'structure' || $tag['attributes']['type'] == 'category') { // force loading dictionary for all elements in structure (for the current language) nvweb_menu_load_dictionary(); if (!is_numeric($tag['attributes']['id'])) { // maybe it's a property name instead of a category id $tag['attributes']['id'] = nvweb_properties(array('property' => $tag['attributes']['property'])); } $content = $structure['dictionary'][$tag['attributes']['id']]; } else { if ($tag['attributes']['type'] == 'item') { $tmp = webdictionary::load_element_strings('item', $tag['attributes']['id']); $content = $tmp[$current['lang']]['title']; } } } else { $content = $dictionary[$tag['attributes']['id']]; } if (empty($content)) { $content = $tag['attributes']['label']; } if (empty($content)) { $content = $tag['attributes']['default']; } break; case 'request': if (!empty($tag['attributes']['name'])) { $content = $_REQUEST[$tag['attributes']['name']]; } else { // deprecated: use "request" as attribute [will be removed on navigate cms 2.0] $content = $_REQUEST[$tag['attributes']['request']]; } if (is_array($content)) { $content = implode(',', $content); } break; case 'constant': case 'variable': switch ($tag['attributes']['name']) { case "structure": case "category": // retrieve the category ID from current session $tmp = NULL; if ($current['type'] == 'structure') { $tmp = $current['id']; } else { if (!empty($current['category'])) { $tmp = $current['category']; } else { if (!empty($current['object']->category)) { $tmp = $current['object']->category; } } } if (empty($tmp)) { $content = ''; } else { $content = $DB->query_single('text', 'nv_webdictionary', ' node_type = "structure" AND subtype = "title" AND node_id = ' . $tmp . ' AND lang = ' . protect($current['lang']) . ' AND website = ' . $website->id); } break; case "year": $content = date('Y'); break; case "website_name": $content = $website->name; break; case "website_description": $content = $website->metatag_description[$current['lang']]; break; case "lang_code": $content = $current['lang']; break; default: break; } break; case 'php': if (!empty($tag['attributes']['code'])) { eval('$content = ' . $tag['attributes']['code'] . ';'); } break; case 'theme': // compatibility with Navigate < 1.8.9 // deprecated! code will be removed in Navigate 2.0 if ($tag['attributes']['name'] == 'url') { $tag['attributes']['mode'] = 'url'; } else { if ($tag['attributes']['name'] == 'style') { $tag['attributes']['name'] = $tag['attributes']['mode']; $tag['attributes']['mode'] = 'style'; } } // new syntax ("mode" first) switch ($tag['attributes']['mode']) { case "style": $content = $website->theme_options->style; if (!empty($tag['attributes']['name'])) { switch ($tag['attributes']['name']) { case 'name': $content = $website->theme_options->style; break; case 'color': default: // return theme definition file location for the requested substyle if (!empty($website->theme_options->style)) { $content = $theme->styles->{$website->theme_options->style}->{$tag['attributes']['name']}; } if (empty($content)) { // return first available $theme_styles = array_keys(get_object_vars($theme->styles)); $content = $theme->styles->{$theme_styles[0]}->{$tag['attributes']['name']}; } break; } } break; case "url": $content = $idn->encode($website->absolute_path(false)); $content .= NAVIGATE_FOLDER . '/themes/' . $theme->name . '/'; break; } break; default: //var_dump($tag['attributes']['object']); break; } $html = str_replace($tag['full_tag'], $content, $html); } return $html; }
function nvweb_properties_render($property, $vars) { global $website; global $current; global $DB; global $session; global $theme; global $structure; $out = ''; setlocale(LC_ALL, $website->languages[$session['lang']]['system_locale']); // if this property is null (no value assigned (null), (empty) is a value!) // get the default value if (!isset($property->value)) { $property->value = $property->dvalue; } // check multilanguage properties, where the value can be saved in a language but may be (null) in another language if (in_array($property->type, array("text", "textarea", "rich_textarea", "link")) || $property->multilanguage == 'true') { // cast variable as array if (is_object($property->value)) { $property->value = (array) $property->value; } if (!isset($property->value) || !isset($property->value[$current['lang']])) { if (isset($property->dvalue->{$current['lang']})) { $property->value[$current['lang']] = $property->dvalue->{$current['lang']}; } else { if (!is_array($property->value)) { $property->value = array(); } $property->value[$current['lang']] = $property->dvalue; } } } switch ($property->type) { case 'value': $out = $property->value; break; case 'decimal': $out = $property->value; if (isset($vars['precision'])) { $out = number_format($property->value, $vars['precision']); } break; case 'boolean': $out = $property->value; break; case 'option': $options = mb_unserialize($property->options); $options = (array) $options; switch (@$vars['return']) { case 'value': $out = $property->value; break; default: $out = $theme->t($options[$property->value]); } break; case 'moption': $options = mb_unserialize($property->options); $selected = explode(",", $property->value); switch (@$vars['return']) { case 'value': case 'values': $out = $property->value; break; default: $buffer = array(); foreach ($selected as $seloption) { $buffer[] = '<span>' . $theme->t($options[$seloption]) . '</span>'; } $out .= implode(', ', $buffer); } break; case 'text': $out = htmlspecialchars($property->value[$current['lang']]); break; case 'textarea': $out = nl2br(htmlspecialchars($property->value[$current['lang']])); break; case 'rich_textarea': $out = $property->value[$current['lang']]; break; case 'source_code': if (@$property->multilanguage == 'true' || $property->multilanguage == '1') { $out = $property->value[$current['lang']]; } else { $out = $property->value; } break; case 'date': if (!empty($vars['format'])) { $out = Encoding::toUTF8(strftime($vars['format'], $property->value)); } else { $out = date($website->date_format, $property->value); } break; case 'datetime': if (!empty($vars['format'])) { $out = Encoding::toUTF8(strftime($vars['format'], $property->value)); } else { $out = date($website->date_format . ' H:i', $property->value); } break; case 'link': // split title and link $link = explode('##', $property->value[$current['lang']]); if (is_array($link)) { $target = @$link[2]; $title = @$link[1]; $link = $link[0]; if (empty($title)) { $title = $link; } } else { $title = $property->value[$current['lang']]; $link = $property->value[$current['lang']]; $target = '_self'; } if (strpos($link, '://') === false) { $link = $website->absolute_path() . $link; } if ($vars['link'] === 'false') { $out = $link; } else { if (isset($vars['return'])) { if ($vars['return'] == 'title') { $out = $title; } else { if ($vars['return'] == 'link' || $vars['return'] == 'url') { $out = $link; } else { if ($vars['return'] == 'target') { $out = $target; } } } } else { $out = '<a href="' . $link . '" target="' . $target . '">' . $title . '</a>'; } } break; case 'image': $add = ''; $extra = ''; if (@$property->multilanguage == 'true' || $property->multilanguage == '1') { $image_id = $property->value[$session['lang']]; } else { $image_id = $property->value; } if (isset($vars['width'])) { $add .= ' width="' . $vars['width'] . '" '; $extra .= '&width=' . $vars['width']; } if (isset($vars['height'])) { $add .= ' height="' . $vars['height'] . '" '; $extra .= '&height=' . $vars['height']; } if (isset($vars['border'])) { $extra .= '&border=' . $vars['border']; } if (isset($vars['quality'])) { $extra .= '&quality=' . $vars['quality']; } $img_url = NVWEB_OBJECT . '?type=image&id=' . $image_id . $extra; if (empty($image_id)) { $out = ''; } else { if ($vars['return'] == 'url') { $out = $img_url; } else { // retrieve additional info (title/alt), if available if (is_numeric($image_id)) { $f = new file(); $f->load($image_id); $ftitle = $f->title[$current['lang']]; $falt = $f->description[$current['lang']]; if (!empty($ftitle)) { $add .= ' title="' . $ftitle . '" '; } if (!empty($falt)) { $add .= ' alt="' . $falt . '" '; } } $out = '<img class="' . $vars['class'] . '" src="' . $img_url . '" ' . $add . ' />'; } } break; case 'file': if (!empty($property->value)) { $file = $DB->query_single('name', 'nv_files', ' id = ' . protect($property->value) . ' AND website = ' . $website->id); if ($vars['return'] == 'url' || $vars['return'] == 'url-download') { $out = NVWEB_OBJECT . '?type=file&id=' . $property->value . '&disposition=attachment'; } else { if ($vars['return'] == 'url-inline') { $out = NVWEB_OBJECT . '?type=file&id=' . $property->value . '&disposition=inline'; } else { $out = '<a href="' . NVWEB_OBJECT . '?type=file&id=' . $property->value . '&disposition=attachment">' . $file . '</a>'; } } } break; case 'comment': $out = $property->value; break; case 'coordinates': $coordinates = explode('#', $property->value); $out = implode(',', $coordinates); break; case 'rating': // half stars are always enabled (ratings fixed to 0..10) $out = $property->value; // we want nearest integer down if ($vars['option'] == 'floor') { $out = floor($out / 2); } break; case 'color': $out = $property->value; break; case 'video': // value may be a numeric file ID or a provider#id structure, f.e. youtube#3MteSlpxCpo // compatible providers: file,youtube,vimeo if (@$property->multilanguage == 'true' || $property->multilanguage == '1') { $video_id = $property->value[$session['lang']]; } else { $video_id = $property->value; } $provider = ''; $reference = ''; $add = ''; if (isset($vars['width'])) { $add .= ' width="' . $vars['width'] . '" '; } if (isset($vars['height'])) { $add .= ' height="' . $vars['height'] . '" '; } $url_add = '&type=image'; if (isset($vars['width'])) { $url_add .= '&width=' . $vars['width'] . ''; } if (isset($vars['height'])) { $url_add .= '&height=' . $vars['height'] . ''; } if (isset($vars['border'])) { $url_add .= '&border=' . $vars['border'] . ''; } if (strpos($video_id, '#') !== false) { list($provider, $reference) = explode("#", $video_id); } if ($provider == 'file') { $video_id = $reference; } $file = new file(); if (is_numeric($video_id)) { $file->load($video_id); $embed = file::embed('file', $file, $add); } else { if ($provider == 'youtube') { $embed = file::embed('youtube', $reference, $add); if (!empty($vars['part']) || $vars['part'] != 'embed') { $file->load_from_youtube($reference); } } else { if ($provider == 'vimeo') { $embed = file::embed('vimeo', $reference, $add); if (!empty($vars['part']) || $vars['part'] != 'embed') { $file->load_from_vimeo($reference); } } } } switch (@$vars['return']) { case 'title': $out = $file->title; break; case 'mime': $out = $file->mime; break; case 'author': if (is_numeric($file->uploaded_by)) { $out = $website->name; } else { $out = $file->uploaded_by; } break; case 'path': case 'url': $out = $file->extra['link']; break; case 'thumbnail_url': $out = file::file_url($file->extra['thumbnail_cache']) . $url_add; break; case 'thumbnail': $out = '<img src="' . file::file_url($file->extra['thumbnail_cache']) . $url_add . '" class="' . $vars['class'] . '" ' . $add . ' />'; break; case 'reference': $out = $reference; break; case 'provider': $out = $provider; break; case 'embed': default: $out = $embed; } break; case 'article': // TO DO break; case 'category': $return = @$vars['return']; switch ($return) { case 'title': case 'name': nvweb_menu_load_dictionary(); $out = $structure['dictionary'][$property->value]; break; case 'url': case 'link': $out = nvweb_source_url('structure', $property->value); break; default: $out = $property->value; } break; case 'categories': $return = @$vars['return']; $value = explode(",", $property->value); $position = intval(@vars['position']) + 0; switch ($return) { case 'title': case 'name': nvweb_menu_load_dictionary(); $out = $structure['dictionary'][$value[$position]]; break; case 'url': case 'link': $out = nvweb_source_url('structure', $value[$position]); break; default: $out = $property->value; } break; case 'country': $return = @$vars['return']; switch ($return) { case 'name': $countries = property::countries(); $out = $countries[$property->value]; break; case 'id': case 'code': default: $out = $property->value; break; } break; case 'elements': $out = $property->value; break; case 'element': case 'item': // deprecated $return = @$vars['return']; switch ($return) { case 'title': $item = new item(); $item->load($property->value); $out = $item->dictionary[$current['lang']]['title']; break; case 'url': case 'path': $out = nvweb_source_url('item', $property->value, $current['lang']); break; case 'section': $item = new item(); $item->load($property->value); $out = $item->dictionary[$current['lang']]['section-' . $vars['section']]; break; case 'property': $params = array(); foreach ($vars as $attr_name => $attr_value) { if (strpos($attr_name, 'element-property-') === 0) { $attr_name = str_replace('element-property-', '', $attr_name); $params[$attr_name] = $attr_value; } else { if ($attr_name == 'element-property') { $params['property'] = $attr_value; } } } // default parameters $params['mode'] = 'item'; $params['id'] = $property->value; $out = nvweb_properties($params); break; case 'id': default: $out = $property->value; break; } break; default: } return $out; }