function nvweb_tags($vars = array()) { global $website; global $DB; global $current; $out = ''; switch ($vars['mode']) { case 'top': case 'random': $search_url = nvweb_source_url('theme', 'search'); if ($search_url == $website->absolute_path()) { $search_url = NVWEB_ABSOLUTE . '/nvtags'; } $search_parameter = 'q'; if (!empty($vars['request'])) { $search_parameter = $vars['request']; } $search_url .= '?' . $search_parameter . '='; $categories = array(); if (!empty($vars['categories'])) { $categories = preg_split('/[,\\s]+/', $vars['categories']); $categories = array_merge($categories, nvweb_menu_get_children($categories)); $categories = array_filter($categories); } $tags = nvweb_tags_retrieve($vars['items'], $categories, $vars['mode']); $out = array(); $extra = ''; if (!empty($vars['class'])) { $extra = ' class="' . $vars['class'] . '" '; } foreach ($tags as $tag => $times) { if (empty($tag)) { continue; } if ($vars['tag'] == 'li') { $out[] = '<li><a href="' . $search_url . $tag . '" count="' . $times . '" ' . $extra . '>' . $tag . '</a></li>'; } else { if ($vars['tag'] == 'span') { $out[] = '<span count="' . $times . '" ' . $extra . '>' . $tag . '</span>' . $vars['separator']; } else { $out[] = '<a href="' . $search_url . $tag . '" count="' . $times . '" ' . $extra . '>' . $tag . '</a>' . $vars['separator']; } } } $out = implode("\n", $out); break; } return $out; }
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; }
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, '…', $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; }
function metaWeblog_getPost($args) { global $DB; global $session; $out = array(); list($post_id, $username, $password) = $args; $item = new item(); $item->load(intval($post_id)); $website_id = $item->website; $website = new website(); $website->load($website_id); // check auth if (metaWeblog_userAllowed($username, $password, $website_id)) { if ($item->embedding == 1) { $link = nvweb_source_url('structure', $item->category, $session['lang']); } else { $link = $item->link($session['lang']); } $category = new structure(); $category->load($item->category); $content = $item->dictionary[$session['lang']]['section-main']; $content = nvweb_template_fix_download_paths($content); if (empty($item->date_to_display)) { $item->date_to_display = $item->date_created; } $out = array("postid" => $item->id, "userid" => $item->author, "dateCreated" => new IXR_Date($item->date_to_display), "category" => $item->category, "title" => $item->dictionary[$session['lang']]['title'], "description" => $content, "url" => $link, "permalink" => $link, "mt_keywords" => $item->dictionary[$session['lang']]['tags']); } else { $out = new IXR_Error(401, "User not allowed."); } return $out; }
function nvweb_template_convert_nv_paths($html) { preg_match_all("/nv:\\/\\/(element|elements|structure|category)\\/([0-9]+)+/", $html, $matches); if (!empty($matches) && !empty($matches[0])) { $matches = $matches[0]; foreach ($matches as $match) { $parts = explode('/', str_replace('nv://', '', $match)); $url = ""; switch ($parts[0]) { case 'element': case 'item': case 'elements': $url = nvweb_source_url("element", $parts[1]); break; case 'structure': case 'category': $url = nvweb_source_url("structure", $parts[1]); break; default: // ignore this url } if (!empty($url)) { $html = str_replace(array('"' . $match . '"', "'" . $match . "'"), array('"' . $url . '"', "'" . $url . "'"), $html); } } } return $html; }
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; }
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; }
function nvweb_comments($vars = array()) { global $website; global $DB; global $current; global $webgets; global $dictionary; global $webuser; global $theme; global $events; global $session; $webget = 'comments'; if (!isset($webgets[$webget])) { $webgets[$webget] = array(); global $lang; if (empty($lang)) { $lang = new language(); $lang->load($current['lang']); } // default translations $webgets[$webget]['translations'] = array('post_a_comment' => t(379, 'Post a comment'), 'name' => t(159, 'Name'), 'email' => t(44, 'E-Mail'), 'website' => t(177, 'Website'), 'message' => t(380, 'Message'), 'email_will_not_be_published' => t(381, 'E-Mail will not be published'), 'submit' => t(382, 'Submit'), 'sign_in_or_sign_up_to_post_a_comment' => t(383, 'Sign in or Sign up to post a comment'), 'comments_on_this_entry_are_closed' => t(384, 'Comments on this entry are closed'), 'please_dont_leave_any_field_blank' => t(385, 'Please don\'t leave any field blank'), 'your_comment_has_been_received_and_will_be_published_shortly' => t(386, 'Your comment has been received and will be published shortly'), 'new_comment' => t(387, 'New comment'), 'review_comments' => t(388, 'Review comments')); // theme translations // if the web theme has custom translations for this string subtypes, use it (for the user selected language) /* just add the following translations to your json theme dictionary: "post_a_comment": "Post a comment", "name": "Name", "email": "E-Mail", "website": "Website", "message": "Message", "email_will_not_be_published": "E-Mail will not be published", "submit": "Submit", "sign_in_or_sign_up_to_post_a_comment": "Sign in or Sign up to post a comment", "comments_on_this_entry_are_closed": "Comments on this entry are closed", "please_dont_leave_any_field_blank": "Please don't leave any field blank", "your_comment_has_been_received_and_will_be_published_shortly": "Your comment has been received and will be published shortly", "new_comment": "New comment", "review_comments": "Review comments" */ if (!empty($website->theme) && method_exists($theme, 't')) { foreach ($webgets[$webget]['translations'] as $code => $text) { $theme_translation = $theme->t($code); if (!empty($theme_translation) && $theme_translation != $code) { $webgets[$webget]['translations'][$code] = $theme_translation; } } } } // set default callback if (empty($vars['callback'])) { $vars['callback'] = 'alert'; } // check callback attributes $callback = $vars['callback']; if (!empty($vars['alert_callback'])) { $callback = $vars['alert_callback']; } else { if (!empty($vars['callback_alert'])) { $callback = $vars['callback_alert']; } } $callback_error = $callback; if (!empty($vars['error_callback'])) { $callback_error = $vars['error_callback']; } else { if (!empty($vars['callback_error'])) { $callback_error = $vars['callback_error']; } } $out = ''; // if the current page belongs to a structure entry // we need to get the associated elements to retrieve and post its comments // (because structure entry pages can't have associated comments) // so, ONLY the FIRST element associated to a category can have comments in a structure entry page // (of course if the element has its own page, it can have its own comments) $element = $current['object']; if ($current['type'] == 'structure') { if (empty($current['structure_elements'])) { $current['structure_elements'] = $element->elements(); } $element = $current['structure_elements'][0]; } switch (@$vars['mode']) { case 'process': if (isset($_GET['nv_approve_comment'])) { // process 1-click comment approval $comment = new comment(); $comment->load($_GET['id']); if (!empty($comment->id) && $comment->status == -1) { $hash = $_GET['hash']; if ($hash == sha1($comment->id . $comment->email . APP_UNIQUE . serialize($website->contact_emails))) { // hash check passed $comment->status = 0; $comment->save(); $response = t(555, "Item has been successfully published."); if ($vars['notify'] == 'inline' || $callback == 'inline') { $out = '<div class="comment-success">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback . '("' . $response . '");'); } } } else { $response = t(344, "Security error"); if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } } } else { $response = t(56, "Unexpected error"); if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } } } if (isset($_GET['nv_remove_comment'])) { // process 1-click comment removal $comment = new comment(); $comment->load($_GET['id']); if (!empty($comment->id) && $comment->status == -1) { $hash = $_GET['hash']; if ($hash == sha1($comment->id . $comment->email . APP_UNIQUE . serialize($website->contact_emails))) { // hash check passed $comment->delete(); $response = t(55, "Item successfully deleted"); if ($vars['notify'] == 'inline' || $callback == 'inline') { $out = '<div class="comment-success">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback . '("' . $response . '");'); } } } else { $response = t(344, "Security error"); if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } } } else { $response = t(56, "Unexpected error"); if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } } } if ($_REQUEST['form-type'] == 'comment-reply' || isset($_POST[$vars['field-message']])) { // add comment if (empty($vars['field-name'])) { $vars['field-name'] = 'reply-name'; } if (empty($vars['field-email'])) { $vars['field-email'] = 'reply-email'; } if (empty($vars['field-url'])) { $vars['field-url'] = 'reply-url'; } if (empty($vars['field-message'])) { $vars['field-message'] = 'reply-message'; } if (!empty($vars['element'])) { $element = $vars['element']; } $comment_name = @$_REQUEST[$vars['field-name']]; $comment_email = @$_REQUEST[$vars['field-email']]; $comment_url = @$_REQUEST[$vars['field-url']]; $comment_message = @$_REQUEST[$vars['field-message']]; if ((empty($comment_name) || empty($comment_email)) && empty($webuser->id) || empty($comment_message)) { $response = $webgets[$webget]['translations']['please_dont_leave_any_field_blank']; if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } return $out; } $status = -1; // new comment, not approved if (empty($element->comments_moderator)) { $status = 0; } // all comments auto-approved // remove any <nv /> or {{nv}} tag $comment_name = core_remove_nvtags($comment_name); $comment_name = strip_tags($comment_name); $comment_message = core_remove_nvtags($comment_message); $comment = new comment(); $comment->id = 0; $comment->website = $website->id; $comment->item = $element->id; $comment->user = empty($webuser->id) ? 0 : $webuser->id; $comment->name = $comment_name; $comment->email = filter_var($comment_email, FILTER_SANITIZE_EMAIL); $comment->url = filter_var($comment_url, FILTER_SANITIZE_URL); $comment->ip = core_ip(); $comment->date_created = core_time(); $comment->date_modified = 0; $comment->status = $status; $comment->message = $comment_message; $properties = array(); // check if there are comment properties values if (isset($vars['field-properties-prefix'])) { // check every possible property $e_properties = property::elements($element->template, 'comment'); for ($ep = 0; $ep < count($e_properties); $ep++) { if (isset($_POST[$vars['field-properties-prefix'] . $e_properties[$ep]->id])) { $properties[$e_properties[$ep]->id] = $_POST[$vars['field-properties-prefix'] . $e_properties[$ep]->id]; } } } // trigger the "new_comment" event through the extensions system before inserting it! $extensions_messages = $events->trigger('comment', 'before_insert', array('comment' => $comment, 'properties' => $properties)); foreach ($extensions_messages as $ext_name => $ext_result) { if (isset($ext_result['error'])) { $response = $ext_result['error']; if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } return $out; } } $comment->insert(); if (!empty($properties)) { property::save_properties_from_array('comment', $comment->id, $element->template, $properties); } // reload the element to retrieve the new comments $element = new item(); $element->load($comment->item); if ($current['type'] == 'item' && !isset($vars['element'])) { $current['object'] = $element; } // trigger the "new_comment" event through the extensions system $events->trigger('comment', 'after_insert', array('comment' => &$comment, 'properties' => $properties)); if (!empty($comment->id)) { if ($status == -1) { $response = $webgets[$webget]['translations']['your_comment_has_been_received_and_will_be_published_shortly']; if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-success">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback . '("' . $response . '");'); } } } else { $response = $webgets[$webget]['translations']['your_comment_has_been_received_and_will_be_published_shortly']; if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-success">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback . '("' . $response . '");'); } } } } $notify_addresses = $website->contact_emails; if (!empty($element->comments_moderator)) { $notify_addresses[] = user::email_of($element->comments_moderator); } $hash = sha1($comment->id . $comment->email . APP_UNIQUE . serialize($website->contact_emails)); $base_url = nvweb_source_url('element', $element->id); // default colors $background_color = '#E5F1FF'; $text_color = '#595959'; $title_color = '#595959'; $background_color_db = $DB->query_single('value', 'nv_permissions', 'name = ' . protect("nvweb.comments.background_color") . ' AND website = ' . protect($website->id), 'id DESC'); $text_color_db = $DB->query_single('value', 'nv_permissions', 'name = ' . protect("nvweb.comments.text_color") . ' AND website = ' . protect($website->id), 'id DESC'); $title_color_db = $DB->query_single('value', 'nv_permissions', 'name = ' . protect("nvweb.comments.titles_color") . ' AND website = ' . protect($website->id), 'id DESC'); if (!empty($background_color_db)) { $background_color = str_replace('"', '', $background_color_db); } if (!empty($text_color_db)) { $text_color = str_replace('"', '', $text_color_db); } if (!empty($title_color_db)) { $title_color = str_replace('"', '', $title_color_db); } $message = navigate_compose_email(array(array('title' => t(9, 'Content'), 'content' => $element->dictionary[$current['lang']]['title']), array('title' => $webgets[$webget]['translations']['name'], 'content' => $comment_name . @$webuser->username), array('title' => $webgets[$webget]['translations']['email'], 'content' => $comment_email . @$webuser->email), array('title' => $webgets[$webget]['translations']['website'], 'content' => $comment_url . @$webuser->social_website), array('title' => $webgets[$webget]['translations']['message'], 'content' => nl2br($comment_message)), array('footer' => '<a href="' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?wid=' . $website->id . '&fid=10&act=2&tab=5&id=' . $element->id . '"><strong>' . $webgets[$webget]['translations']['review_comments'] . '</strong></a>' . ' | ' . '<a style=" color: #008830" href="' . $base_url . '?nv_approve_comment&id=' . $comment->id . '&hash=' . $hash . '">' . t(258, "Publish") . '</a>' . ' | ' . '<a style=" color: #FF0090" href="' . $base_url . '?nv_remove_comment&id=' . $comment->id . '&hash=' . $hash . '">' . t(525, "Remove comment (without confirmation)") . '</a>')), array('background' => $background_color, 'title-color' => $title_color, 'content-color' => $text_color)); // trying to implement One-Click actions (used in Google GMail) // You need to be registered with Google first: https://developers.google.com/gmail/markup/registering-with-google $one_click_actions = ' <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "name": "' . $webgets[$webget]['translations']['review_comments'] . '", "url": "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?wid=' . $website->id . '&fid=10&act=2&tab=5&id=' . $element->id . '" } } </script> '; $message = '<html><head>' . $one_click_actions . '</head><body>' . $message . '</body></html>'; foreach ($website->contact_emails as $contact_address) { @nvweb_send_email($website->name . ' | ' . $webgets[$webget]['translations']['new_comment'], $message, $contact_address, null, true); } } break; case 'reply': if ($element->comments_enabled_to == 2 && empty($webuser->id)) { // Post a comment form (unsigned users) $out = ' <div class="comments-reply"> <div><div class="comments-reply-info">' . $webgets[$webget]['translations']['post_a_comment'] . '</div></div> <br /> <form action="' . NVWEB_ABSOLUTE . '/' . $current['route'] . '" method="post"> <input type="hidden" name="form-type" value="comment-reply" /> <div class="comments-reply-field"><label>' . $webgets[$webget]['translations']['name'] . '</label> <input type="text" name="reply-name" value="" /></div> <div class="comments-reply-field"><label>' . $webgets[$webget]['translations']['email'] . ' *</label> <input type="text" name="reply-email" value="" /></div> <div class="comments-reply-field"><label>' . $webgets[$webget]['translations']['message'] . '</label> <textarea name="reply-message"></textarea></div> <!-- {{navigate-comments-reply-extra-fields-placeholder}} --> <div class="comments-reply-field comments-reply-field-info-email"><label> </label> * ' . $webgets[$webget]['translations']['email_will_not_be_published'] . '</div> <div class="comments-reply-field comments-reply-field-submit"><input class="comments-reply-submit" type="submit" value="' . $webgets[$webget]['translations']['submit'] . '" /></div> </form> </div> '; $extensions_messages = $events->trigger('comment', 'reply_extra_fields', array('html' => &$out)); // add any extra field generated if (!empty($extensions_messages)) { $extra_fields = array_map(function ($v) { return $v; }, array_values($extensions_messages)); $out = str_replace('<!-- {{navigate-comments-reply-extra-fields-placeholder}} -->', implode("\n", $extra_fields), $out); } } else { if ($element->comments_enabled_to > 0 && !empty($webuser->id)) { // Post a comment form (signed in users) if (empty($vars['avatar_size'])) { $vars['avatar_size'] = 32; } $avatar_url = NVWEB_OBJECT . '?type=blank'; if (!empty($webuser->avatar)) { $avatar_url = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $webuser->avatar . '&disposition=inline&width=' . $vars['avatar_size'] . '&height=' . $vars['avatar_size']; } $out = ' <div class="comments-reply"> <div><div class="comments-reply-info">' . $webgets[$webget]['translations']['post_a_comment'] . '</div></div> <br /> <form action="' . NVWEB_ABSOLUTE . '/' . $current['route'] . '" method="post"> <input type="hidden" name="form-type" value="comment-reply" /> <div class="comments-reply-field"><label style="display: none;"> </label> <img src="' . $avatar_url . '" width="' . $vars['avatar_size'] . '" height="' . $vars['avatar_size'] . '" align="absmiddle" /> <span class="comments-reply-username">' . $webuser->username . '</span><a class="comments-reply-signout" href="?webuser_signout">(x)</a></div> <br /> <div class="comments-reply-field"><label>' . $webgets[$webget]['translations']['message'] . '</label> <textarea name="reply-message"></textarea></div> <!-- {{navigate-comments-reply-extra-fields-placeholder}} --> <div class="comments-reply-field-submit"><input class="comments-reply-submit" type="submit" value="' . $webgets[$webget]['translations']['submit'] . '" /></div> </form> </div> '; $extensions_messages = $events->trigger('comment', 'reply_extra_fields', array('html' => $out)); // add any extra field generated if (!empty($extensions_messages)) { $extra_fields = array_map(function ($v) { return $v; }, array_values($extensions_messages)); $out = str_replace('<!-- {{navigate-comments-reply-extra-fields-placeholder}} -->', implode("\n", $extra_fields), $out); } } else { if ($element->comments_enabled_to == 1) { $out = '<div class="comments-reply"> <div class="comments-reply-info">' . $webgets[$webget]['translations']['sign_in_or_sign_up_to_post_a_comment'] . '</div> </div>'; } else { $out = '<div class="comments-reply"> <div class="comments-reply-info">' . $webgets[$webget]['translations']['comments_on_this_entry_are_closed'] . '</div> </div>'; } } } break; case 'comments': setlocale(LC_ALL, $website->languages[$session['lang']]['system_locale']); list($comments, $comments_total) = nvweb_comments_list(0, NULL, NULL, $vars['order']); // get all comments of the current entry if (empty($vars['avatar_size'])) { $vars['avatar_size'] = '48'; } if (empty($vars['date_format'])) { $vars['date_format'] = '%d %B %Y %H:%M'; } for ($c = 0; $c < $comments_total; $c++) { $avatar = $comments[$c]->avatar; if (!empty($avatar)) { $avatar = '<img src="' . NVWEB_OBJECT . '?type=image&id=' . $avatar . '" width="' . $vars['avatar_size'] . 'px" height="' . $vars['avatar_size'] . 'px"/>'; } else { $avatar = '<img src="data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="' . $vars['avatar_size'] . 'px" height="' . $vars['avatar_size'] . 'px"/>'; } $comment = new comment(); $comment->load_from_resultset(array($comments[$c])); $depth = 'data-depth="' . $comment->depth() . '"'; $out .= ' <div class="comment"' . $depth . '> <div class="comment-avatar">' . $avatar . '</div> <div class="comment-username">' . (!empty($comments[$c]->username) ? $comments[$c]->username : $comments[$c]->name) . '</div> <div class="comment-date">' . Encoding::toUTF8(strftime($vars['date_format'], $comments[$c]->date_created)) . '</div> <div class="comment-message">' . nl2br($comments[$c]->message) . '</div> <div style="clear:both"></div> </div> '; } break; } return $out; }
function nvweb_archive($vars = array()) { global $website; global $DB; global $current; global $webgets; $webget = "archive"; $out = array(); $permission = !empty($_SESSION['APP_USER#' . APP_UNIQUE]) ? 1 : 0; $access = !empty($current['webuser']) ? 1 : 2; if (empty($vars['categories'])) { if ($current['type'] == 'structure') { $categories = array($current['id']); } else { $categories = array($current['object']->category); } $categories = nvweb_menu_get_children($categories); } else { if (!empty($vars['categories'])) { if (!is_numeric($vars['categories']) && strpos($vars['categories'], ',') === false) { // we want to get the categories from a specific property of the current page $categories = nvweb_properties(array('property' => $vars['categories'])); if (empty($categories) && @$vars['nvlist_parent_vars']['source'] == 'block_group') { $categories = nvweb_properties(array('mode' => 'block_group_block', 'property' => $vars['categories'], 'id' => $vars['nvlist_parent_item']->id, 'uid' => $vars['nvlist_parent_item']->uid)); } if (!is_array($categories)) { $categories = explode(',', $categories); $categories = array_filter($categories); // remove empty elements } } else { $categories = explode(',', $vars['categories']); $categories = array_filter($categories); // remove empty elements } if ($vars['children'] == 'true') { $categories = nvweb_menu_get_children($categories); } } } if ($vars['search_page_type'] == 'theme') { $archive_url = $website->absolute_path() . '/nvsearch'; } else { $archive_url = nvweb_source_url($vars['search_page_type'], $vars['search_page_id']); } if (strpos($vars['nvweb_html'], 'jquery') === false) { $out[] = '<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>'; } // retrieve posts number by year, month, and... // checking if there are available in the current language (items must have custom paths assigned) $DB->query(' SELECT COUNT(i.id) AS total, MONTH(FROM_UNIXTIME(COALESCE(NULLIF(i.date_to_display, 0), i.date_created))) as month, YEAR(FROM_UNIXTIME(COALESCE(NULLIF(i.date_to_display, 0), i.date_created))) as year FROM nv_items i WHERE i.website = ' . $website->id . ' AND i.permission <= ' . $permission . ' AND (i.date_published = 0 OR i.date_published < ' . core_time() . ') AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ') AND i.category IN(' . implode(",", $categories) . ') AND (i.access = 0 OR i.access = ' . $access . ') AND 0 < ( SELECT COUNT(p.id) FROM nv_paths p WHERE p.website = ' . $website->id . ' AND p.type = "item" AND p.object_id = i.id AND p.lang = "' . $current['lang'] . '" ) GROUP BY year, month ORDER BY year DESC, month DESC '); $dataset = $DB->result(); switch (@$vars['mode']) { case 'month': $out[] = nvweb_archive_render('month', $dataset, $archive_url, $categories); break; case 'year': $type = 'year'; if ($vars['collapsed'] == 'true') { $type = 'year-collapsed'; } $out[] = nvweb_archive_render($type, $dataset, $archive_url, $categories); break; case 'adaptive': default: // let the webget decide the render type // ---> less or equal than 12 months in the list: month view if (count($dataset) <= 12) { $out[] = nvweb_archive_render('month', $dataset, $archive_url, $categories); } else { // year view $out[] = nvweb_archive_render('year', $dataset, $archive_url, $categories); } break; } $out = implode("\n", $out); return $out; }