<?php nvweb_webget_load('properties'); 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] // |
function nvweb_ajax() { global $website; global $theme; nvweb_webget_load($theme->name); $fname = 'nvweb_' . $theme->name . '_nvajax'; if (function_exists($fname)) { $content = $fname(); } }
<?php require_once NAVIGATE_PATH . '/lib/external/force-utf8/Encoding.php'; nvweb_webget_load("menu"); nvweb_webget_load("list"); 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
function nvweb_xmlrpc() { /* Functions defining the behaviour of the server */ nvweb_webget_load('menu'); nvweb_webget_load('content'); function metaWeblog_getUsersBlogs($args) { global $DB; $out = array(); list($appkey, $username, $password) = $args; $user = new user(); $error = !$user->authenticate($username, $password); if (!empty($error) || $user->blocked == '1') { $out = new IXR_Error(401, "User not allowed."); } else { $websites_ids = $user->websites; if (empty($websites_ids)) { // get all websites $DB->query('SELECT id FROM nv_websites WHERE permission = 0'); // only public websites $websites_ids = $DB->result(); } if (is_array($websites_ids)) { foreach ($websites_ids as $wid) { $website = new website(); $website->load($wid); $out[] = array('blogid' => $website->id, 'url' => $website->absolute_path(true) . $website->homepage(), 'blogName' => $website->name, 'isAdmin' => false, 'xmlrpc' => $website->absolute_path(true) . '/xmlrpc'); } } } return $out; } function metaWeblog_getRecentPosts($args) { global $DB; global $session; $out = array(); list($website_id, $username, $password, $number_of_posts) = $args; if (empty($number_of_posts)) { $number_of_posts = 50; } // check auth if (metaWeblog_userAllowed($username, $password, $website_id)) { $DB->query(' SELECT id FROM nv_items WHERE website = ' . $website_id . ' AND permission < 2 ORDER BY date_modified DESC LIMIT ' . $number_of_posts . ' '); $posts = $DB->result(); foreach ($posts as $post) { $item = new item(); $item->load($post->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 metaWeblog_getCategories($args) { global $DB; global $session; $out = array(); list($website_id, $username, $password) = $args; // check auth if (metaWeblog_userAllowed($username, $password, $website_id)) { // get all public categories $DB->query(' SELECT id FROM nv_structure WHERE website = ' . protect($website_id) . ' AND permission < 2 ORDER BY parent ASC, position ASC '); $categories = $DB->result(); $website = new website(); $website->load($website_id); foreach ($categories as $category) { $cat = new structure(); $cat->load($category->id); $url = ''; if ($cat->paths[$session['lang']]) { $url = $website->absolute_path(true) . $cat->paths[$session['lang']]; } $out[] = array("categoryId" => $cat->id, "parentId" => $cat->parent, "categoryName" => $cat->dictionary[$session['lang']]['title'], "categoryDescription" => $cat->template, "htmlUrl" => $url, "rssUrl" => "", "title" => $cat->dictionary[$session['lang']]['title'], "description" => $cat->template); } } else { $out = new IXR_Error(401, "User not allowed."); } return $out; } // Makes a new post to a designated weblog using the MetaWeblog API. Returns postid as a string function metaWeblog_newPost($args) { global $DB; global $session; $out = array(); list($website_id, $username, $password, $post, $publish) = $args; // check auth if (metaWeblog_userAllowed($username, $password, $website_id)) { $category_name = $post['categories']; $category = ""; // category name is text, we have to find the category ID if (is_array($category_name)) { $category_name = array_shift($category_name); $DB->query(' SELECT s.id FROM nv_structure s WHERE s.website = ' . intval($website_id) . ' AND s.id IN ( SELECT w.node_id FROM nv_webdictionary w WHERE w.website = ' . intval($website_id) . ' AND w.node_type = "structure" AND w.subtype = "title" AND w.text LIKE ' . protect($category_name) . ' ) '); $category = $DB->result('id'); $category = $category[0]; if (!isset($post['post_type']) || empty($post['post_type'])) { $post['post_type'] = 'post'; } } $template = 'content'; $association = 'free'; $embedded = '1'; if ($post['post_type'] == 'post') { $template = 'blog_entry'; $association = 'category'; $embedded = '0'; } if (empty($post['dateCreated'])) { $post['dateCreated'] = date("c", time()); } if (!isset($post['mt_text_more'])) { $post['mt_text_more'] = ""; } $item = new item(); $item->association = $association; $item->template = $template; $item->category = $category; $item->embedding = $embedded; $item->permission = $publish ? '0' : '1'; $item->dictionary = array($session['lang'] => array()); $item->paths = array($session['lang'] => array()); $item->date_to_display = strtotime($post['dateCreated']); $item->dictionary[$session['lang']]['title'] = html_entity_decode($post['title']); $item->dictionary[$session['lang']]['section-main'] = $post['description'] . $post['mt_text_more']; $item->dictionary[$session['lang']]['tags'] = $post['mt_keywords']; $item->comments_enabled_to = $post['mt_allow_comments'] == '1' ? 2 : 0; // everybody or nobody $item->save(); $out = $item->id; } else { $out = new IXR_Error(401, "User not allowed."); } return $out; } // Updates and existing post to a designated weblog using the MetaWeblog API. Returns true if completed. function metaWeblog_editPost($args) { global $DB; global $session; $out = array(); list($post_id, $username, $password, $post, $publish) = $args; // check auth if (metaWeblog_userAllowed($username, $password)) { if (!isset($post['mt_text_more'])) { $post['mt_text_more'] = ""; } $item = new item(); $item->load($post_id); $item->dictionary[$session['lang']]['title'] = $post['title']; $item->dictionary[$session['lang']]['section-main'] = $post['description'] . $post['mt_text_more']; if (isset($post['mt_keywords'])) { $item->dictionary[$session['lang']]['tags'] = $post['mt_keywords']; } if (!is_null($publish)) { $item->permission = $publish ? '0' : '1'; } $out = $item->save(); } else { $out = new IXR_Error(401, "User not allowed."); } return $out; } // Retrieves an existing post using the MetaWeblog API. Returns the MetaWeblog struct. 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; } // Deletes a post. /* NOT IMPLEMENTED function metaWeblog_deletePost($args) { global $DB; global $session; $out = array(); list($post_id, $username, $password) = $args; // check auth if(metaWeblog_userAllowed($username, $password, $website_id)) { $out = true; } else { $out = new IXR_Error(401, "User not allowed."); } return $out; } */ // add a new media object function metaWeblog_newMediaObject($args) { global $DB; global $session; $out = array(); list($website_id, $username, $password, $file_struct) = $args; // check auth if (metaWeblog_userAllowed($username, $password, $website_id)) { $file_name_tmp = uniqid('metaweblog-upload-'); file_put_contents(NAVIGATE_PRIVATE . '/' . $website_id . '/files/' . $file_name_tmp, $file_struct['bits']); $file = file::register_upload($file_name_tmp, $file_struct['name'], 0, NULL, false); @unlink(AVIGATE_PRIVATE . '/' . $website_id . '/files/' . $file_name_tmp); // if everything goes fine, file is renamed, so cannot be deleted here $out = array('id' => $file->id, 'file' => $file->name, 'url' => file::file_url($file->id, 'inline'), 'type' => $file->mime); } else { $out = new IXR_Error(401, "User not allowed."); } return $out; } // helper functions function metaWeblog_userAllowed($username, $password, $website_id = NULL) { $user = new user(); $allowed = false; $error = !$user->authenticate($username, $password); if (empty($error) && $user->blocked != '1') { $websites_ids = $user->websites; if (!empty($website_id) && !empty($websites_ids)) { $allowed = in_array($website_id, $websites_ids); } else { $allowed = true; } } return $allowed; } // if we have a RSD request, don't run the XMLRPC server, just give an XML respnse // http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html if (isset($_GET['rsd'])) { global $website; header('Content-Type: text/xml; charset=UTF-8', true); $out = array(); $out[] = '<?xml version="1.0" encoding="UTF-8"?>'; $out[] = '<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">'; $out[] = '<service>'; $out[] = ' <engineName>Navigate CMS</engineName>'; $out[] = ' <engineLink>http://www.navigatecms.com</engineLink>'; $out[] = ' <homePageLink>' . $website->absolute_path() . '</homePageLink>'; $out[] = ' <apis>'; $out[] = ' <api name="MetaWeblog" blogID="' . $website->id . '" preferred="true" apiLink="' . $website->absolute_path() . '/xmlrpc" />'; $out[] = ' <api name="Blogger" blogID="' . $website->id . '" preferred="false" apiLink="' . $website->absolute_path() . '/xmlrpc" />'; $out[] = ' </apis>'; $out[] = '</service>'; $out[] = '</rsd>'; echo implode("\n", $out); } else { // debug // $request = file_get_contents('php://input'); // file_put_contents(NAVIGATE_PATH.'/web/request.txt', $request); // Create the server and map the XML-RPC method names to the relevant functions $server = new IXR_Server(array('metaWeblog.newPost' => 'metaWeblog_newPost', 'metaWeblog.editPost' => 'metaWeblog_editPost', 'metaWeblog.getPost' => 'metaWeblog_getPost', 'metaWeblog.deletePost' => 'metaWeblog_deletePost', 'metaWeblog.newMediaObject' => 'metaWeblog_newMediaObject', 'metaWeblog.getCategories' => 'metaWeblog_getCategories', 'metaWeblog.getRecentPosts' => 'metaWeblog_getRecentPosts', 'metaWeblog.getUsersBlogs' => 'metaWeblog_getUsersBlogs', 'blogger.getUsersBlogs' => 'metaWeblog_getUsersBlogs')); } }
/** * Apply current website theme settings * * Example: <HORIZON_LOGO /> --> Theme logo URL * * @param $template string HTML of the current page * @return string $template HTML of the current page with the theme settings applied */ function nvweb_theme_settings($template) { global $website; if (!empty($website->theme)) { nvweb_webget_load($website->theme); if (function_exists('nvweb_' . $website->theme)) { $out = call_user_func('nvweb_' . $website->theme, array('mode' => 'theme', 'html' => $template)); if (!empty($out)) { $template = $out; } } } return $template; }
function nvweb_list($vars = array()) { global $website; global $DB; global $current; global $cache; global $structure; global $webgets; global $theme; global $webuser; $out = array(); $webget = 'list'; $categories = array(); $exclude = ''; if ($current['type'] == 'item') { $categories = array($current['object']->category); } else { $categories = array($current['object']->id); } if (isset($vars['categories'])) { if ($vars['categories'] == 'all') { $categories = array(0); $vars['children'] = 'true'; } else { if ($vars['categories'] == 'parent') { $parent = $DB->query_single('parent', 'nv_structure', 'id = ' . intval($categories[0])); $categories = array($parent); } else { if ($vars['categories'] == 'nvlist_parent') { if ($vars['nvlist_parent_type'] === 'structure') { $categories = array($vars['nvlist_parent_item']->id); } } else { if (!is_numeric($vars['categories'])) { // if "categories" attribute has a comma, then we suppose it is a list of comma separated values // if not, then maybe we want to get the categories from a specific property of the current page if (strpos($vars['categories'], ',') === false) { $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 we have categories="x" children="true" [to get the children of a category, but not itself] if ($vars['children'] == 'only') { $children = nvweb_menu_get_children($categories); for ($c = 0; $c < count($categories); $c++) { array_shift($children); } $categories = $children; } if (!empty($vars['children']) && intval($vars['children']) > 0) { $children = nvweb_menu_get_children($categories, intval($vars['children'])); for ($c = 0; $c < count($categories); $c++) { array_shift($children); } $categories = $children; } if (empty($vars['items']) || $vars['items'] == '0') { $vars['items'] = 5000; //2147483647; // maximum integer // NOTE: having >5000 items on a page without a paginator is probably a bad idea... disagree? Contact Navigate CMS team! } else { if (!is_numeric($vars['items'])) { $max_items = ""; // the number of items is defined by a property $max_items = nvweb_properties(array('property' => $vars['items'])); if (empty($max_items) && @$vars['nvlist_parent_vars']['source'] == 'block_group') { $max_items = nvweb_properties(array('mode' => 'block_group_block', 'property' => $vars['items'], 'id' => $vars['nvlist_parent_item']->id, 'uid' => $vars['nvlist_parent_item']->uid)); } if (!empty($max_items)) { $vars['items'] = $max_items; } else { $vars['items'] = 500; } // default maximum } } if (!empty($vars['exclude'])) { $exclude = str_replace('current', $current['object']->id, $vars['exclude']); $exclude = explode(',', $exclude); $exclude = array_filter($exclude); if (!empty($exclude)) { if ($vars['source'] == 'structure' || $vars['source'] == 'category') { $exclude = 'AND s.id NOT IN(' . implode(',', $exclude) . ')'; } else { // item $exclude = 'AND i.id NOT IN(' . implode(',', $exclude) . ')'; } } else { $exclude = ''; } } // retrieve entries // calculate the offset of the first element to retrieve // Warning: the paginator applies on all paginated lists on a page (so right now there can only be one in a page) if (empty($_GET['page'])) { $_GET['page'] = 1; } $offset = intval($_GET['page'] - 1) * $vars['items']; // this list does not use paginator, so offset must be always zero if (!isset($vars['paginator']) || $vars['paginator'] == 'false') { $offset = 0; } $permission = !empty($_SESSION['APP_USER#' . APP_UNIQUE]) ? 1 : 0; // public access / webuser based / webuser groups based $access = 2; $access_extra = ''; if (!empty($current['webuser'])) { $access = 1; if (!empty($webuser->groups)) { $access_groups = array(); foreach ($webuser->groups as $wg) { if (empty($wg)) { continue; } $access_groups[] = 's.groups LIKE "%g' . $wg . '%"'; } if (!empty($access_groups)) { $access_extra = ' OR (s.access = 3 AND (' . implode(' OR ', $access_groups) . '))'; } } } // get order type: PARAMETER > NV TAG PROPERTY > DEFAULT (priority given in CMS) $order = @$_REQUEST['order']; if (empty($order)) { $order = @$vars['order']; } if (empty($order)) { // default order: latest $order = 'latest'; } $orderby = nvweb_list_get_orderby($order); $rs = NULL; // TODO: try to optimize nvlist generation to use less memory and increase the maximum number of items if (($vars['source'] == 'structure' || $vars['source'] == 'category') && !empty($categories)) { $orderby = str_replace('i.', 's.', $orderby); $visible = ''; if ($vars['filter'] == 'menu') { $visible = ' AND s.visible = 1 '; } $templates = ""; if (!empty($vars['templates'])) { $templates = explode(",", $vars['templates']); $templates = array_filter($templates); $templates = ' AND s.template IN ("' . implode('","', $templates) . '")'; } $DB->query(' SELECT SQL_CALC_FOUND_ROWS s.id, s.permission, s.date_published, s.date_unpublish, s.date_published as pdate, d.text as title, s.position as position FROM nv_structure s, nv_webdictionary d WHERE s.id IN(' . implode(",", $categories) . ') AND s.website = ' . $website->id . ' AND s.permission <= ' . $permission . ' AND (s.date_published = 0 OR s.date_published < ' . core_time() . ') AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ') AND (s.access = 0 OR s.access = ' . $access . $access_extra . ') AND d.website = s.website AND d.node_type = "structure" AND d.subtype = "title" AND d.node_id = s.id AND d.lang = ' . protect($current['lang']) . ' ' . $templates . ' ' . $visible . ' ' . $exclude . ' ' . $orderby . ' LIMIT ' . $vars['items'] . ' OFFSET ' . $offset); $rs = $DB->result(); $total = $DB->foundRows(); } else { if ($vars['source'] == 'block') { list($rs, $total) = nvweb_blocks(array('type' => $vars['type'], 'number' => $vars['items'], 'mode' => $order == 'random' ? 'random' : 'ordered', 'zone' => 'object')); } else { if ($vars['source'] == 'block_link') { // only useful if this nvlist is inside another nv list of source="block" $block_links = $vars['nvlist_parent_item']->trigger['trigger-links'][$current['lang']]; $rs = array(); if (!is_array($block_links)) { $block_links = array(); } foreach ($block_links as $b_key => $b_data) { if (!is_array($b_data)) { $b_data = array(); } $b_i = 0; foreach ($b_data as $b_ref => $b_value) { if (!isset($rs[$b_i])) { $rs[$b_i] = new stdClass(); } if (!isset($rs[$b_i]->id)) { $rs[$b_i]->id = $b_ref; } $rs[$b_i]->{$b_key} = $b_value; $b_i++; } } $total = count($rs); } else { if ($vars['source'] == 'block_group') { $bg = new block_group(); if (!empty($vars['type'])) { $bg->load_by_code($vars['type']); } if (!empty($bg) && !empty($bg->blocks)) { $rs = array(); foreach ($bg->blocks as $bgb) { unset($bgbo); switch ($bgb['type']) { case 'block': $bgbo = new block(); $bgbo->load($bgb['id']); if (empty($bgbo) || empty($bgbo->type)) { continue; } // check if we can display this block if (nvweb_object_enabled($bgbo)) { // check categories / exclusions if (!empty($bgbo->categories)) { $bgbo_cat_found = false; foreach ($categories as $list_cat) { if (in_array($list_cat, $bgbo->categories)) { $bgbo_cat_found = true; } } if (!$bgbo_cat_found) { // block categories don't match the current list categories, skip this block continue; } } if (!empty($bgbo->exclusions)) { foreach ($categories as $list_cat) { if (in_array($list_cat, $bgbo->exclusions)) { continue; } // skip this block } } $rs[] = $bgbo; } break; case 'block_group_block': $bgba = $theme->block_group_blocks($vars['type']); if (!empty($bgba[$bgb['id']])) { $bgbo = $bgba[$bgb['id']]; $bgbo->uid = $bgb['uid']; $rs[] = clone $bgbo; } break; case 'block_type': // a collection of blocks of the same type list($bgbos, $foo) = nvweb_blocks(array('type' => $bgb['id'], 'mode' => $order == 'random' ? 'random' : 'ordered', 'zone' => 'object')); // add the block type definition, with its title if (count($bgbos) > 0 && isset($bgb['title']) && !empty($bgb['title'])) { $bgb['_object_type'] = 'block_group_block_type'; $rs[] = (object) $bgb; } for ($i = 0; $i < count($bgbos); $i++) { $rs[] = $bgbos[$i]; } break; case 'extension': $rs[] = (object) $bgb; break; } } $total = count($rs); } } else { if ($vars['source'] == 'gallery') { if (!isset($vars['nvlist_parent_type'])) { // get gallery of the current item if ($current['type'] == 'item') { $galleries = $current['object']->galleries; if (!is_array($galleries)) { $galleries = mb_unserialize($galleries); } $rs = $galleries[0]; $total = count($rs); } else { if ($current['type'] == 'structure') { // we need the first item assigned to the structure $access_extra_items = str_replace('s.', 'i.', $access_extra); $templates = ""; if (!empty($vars['templates'])) { $templates = explode(",", $vars['templates']); $templates = array_filter($templates); $templates = ' AND i.template IN ("' . implode('","', $templates) . '")'; } // default source for retrieving items (embedded or not) $DB->query(' SELECT SQL_CALC_FOUND_ROWS i.id FROM nv_items i, nv_structure s, nv_webdictionary d WHERE i.category IN(' . implode(",", $categories) . ') AND 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 s.id = i.category AND (s.date_published = 0 OR s.date_published < ' . core_time() . ') AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ') AND s.permission <= ' . $permission . ' AND (s.access = 0 OR s.access = ' . $access . $access_extra . ') AND (i.access = 0 OR i.access = ' . $access . $access_extra_items . ') AND d.website = i.website AND d.node_type = "item" AND d.subtype = "title" AND d.node_id = i.id AND d.lang = ' . protect($current['lang']) . ' ' . $templates . ' ' . $exclude . ' ORDER BY i.position ASC LIMIT 1 '); $rs = $DB->result(); $tmp = new item(); $tmp->load($rs[0]->id); $rs = $tmp->galleries[0]; $total = count($rs); } } } else { if ($vars['nvlist_parent_type'] == 'item') { $pitem = $vars['nvlist_parent_item']; $rs = $pitem->galleries[0]; $total = count($rs); } } if ($total > 0) { $order = 'priority'; // display images using the assigned priority if (!empty($vars['order'])) { $order = $vars['order']; } $rs = nvweb_gallery_reorder($rs, $order); // prepare format to be parsed by nv list iterator $rs = array_map(function ($k, $v) { $v['file'] = $k; return $v; }, array_keys($rs), array_values($rs)); } } else { if ($vars['source'] == 'rss') { // url may be a property $rss_url = $vars['url']; if (strpos($vars['url'], "http") !== 0) { $rss_url = nvweb_properties(array('property' => $vars['url'])); } list($rs, $total) = nvweb_list_get_from_rss($rss_url, @$vars['cache'], $offset, $vars['items'], $permission, $order); } else { if ($vars['source'] == 'twitter') { list($rs, $total) = nvweb_list_get_from_twitter($vars['username'], @$vars['cache'], $offset, $vars['items'], $permission, $order); } else { if (!empty($vars['source'])) { // CUSTOM data source if ($vars['source'] == 'comment') { $vars['source'] = 'comments'; } $fname = 'nvweb_' . $vars['source'] . '_list'; if ($vars['source'] == 'website_comments') { $vars['source'] = 'comments'; } nvweb_webget_load($vars['source']); if (function_exists($fname)) { list($rs, $total) = $fname($offset, $vars['items'], $permission, $order, $vars); } } } } } } } } } $categories = array_filter($categories); // DATA SOURCE not given or ERROR ===> items if ((empty($vars['source']) || !is_numeric($total)) && !empty($categories)) { /* * TO DO: design decision ... lists should show items from published categories which has unpublished parent? * * Navigate CMS 1.6.7: NO * // we have to check all website UNPUBLISHED categories to keep the list query efficient // there are some cases: // a) Permission is beyond user's level [0=>public, 1=>private, 2=>hidden] // b) Date published is set and the value is before the current time (not yet published) // c) Date unpublish is set and the value is before the current time (no more published) // d) User account level not allowed [0=>everyone, 1=>signed in users, 2=>users NOT signed in] $DB->query(' SELECT id FROM nv_structure WHERE website = '.protect($website->id).' AND ( permission > '.$permission.' OR (date_published > 0 AND '.$website->current_time().' > date_published) OR (date_unpublish > 0 AND '.$website->current_time().' > date_unpublish) OR (access <> 0 AND access <> '.$access.') ) '); $hidden_categories = $DB->result('id'); // now we would have to mark the children categories also as unpublished */ $filters = ''; if (!empty($vars['filter'])) { $filters = nvweb_list_parse_filters($vars['filter'], 'items'); } // reuse structure.access permission $access_extra_items = str_replace('s.', 'i.', $access_extra); $embedded = $vars['embedded'] == 'true' ? '1' : '0'; $templates = ""; if (!empty($vars['templates'])) { $templates = explode(",", $vars['templates']); $templates = array_filter($templates); if ($embedded == '1') { $templates = ' AND s.template IN ("' . implode('","', $templates) . '")'; } else { $templates = ' AND i.template IN ("' . implode('","', $templates) . '")'; } } $columns_extra = ''; if ($vars['order'] == 'comments') { // we need to retrieve the number of comments to apply the order by clause $columns_extra = ', (SELECT COUNT(c.id) FROM nv_comments c WHERE i.id = c.item AND c.website = i.website AND c.status = 0) AS comments_published'; } // default source for retrieving items $query = ' SELECT SQL_CALC_FOUND_ROWS i.id, i.permission, i.date_published, i.date_unpublish, i.date_to_display, COALESCE(NULLIF(i.date_to_display, 0), i.date_created) as pdate, d.text as title, i.position as position, s.position ' . $columns_extra . ' FROM nv_items i, nv_structure s, nv_webdictionary d WHERE i.category IN(' . implode(",", $categories) . ') AND i.website = ' . $website->id . ' AND i.permission <= ' . $permission . ' AND i.embedding = ' . $embedded . ' AND (i.date_published = 0 OR i.date_published < ' . core_time() . ') AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ') AND s.id = i.category AND (s.date_published = 0 OR s.date_published < ' . core_time() . ') AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ') AND s.permission <= ' . $permission . ' AND (s.access = 0 OR s.access = ' . $access . $access_extra . ') AND (i.access = 0 OR i.access = ' . $access . $access_extra_items . ') AND d.website = i.website AND d.node_type = "item" AND d.subtype = "title" AND d.node_id = i.id AND d.lang = ' . protect($current['lang']) . ' ' . $filters . ' ' . $templates . ' ' . $exclude . ' ' . $orderby . ' LIMIT ' . $vars['items'] . ' OFFSET ' . $offset; $DB->query($query); $rs = $DB->result(); $total = $DB->foundRows(); } // now we have all elements that will be shown in the list // let's apply the nvlist template to each one for ($i = 0; $i < count($rs); $i++) { // ignore empty objects if ($vars['source'] != 'gallery' && empty($rs[$i]->id) || $vars['source'] == 'gallery' && empty($rs[$i]['file'])) { continue; } // prepare a standard $item with the current element if ($vars['source'] == 'comments' || $vars['source'] == 'comment') { $item = $rs[$i]; } else { if ($vars['source'] == 'structure' || $vars['source'] == 'category') { $item = new structure(); $item->load($rs[$i]->id); $item->date_to_display = $rs[$i]->pdate; } else { if ($vars['source'] == 'rss' || $vars['source'] == 'twitter' || $vars['source'] == 'block_link') { // item is virtually created $item = $rs[$i]; } else { if ($vars['source'] == 'block' || $vars['source'] == 'block_group') { if (get_class($rs[$i]) == 'block') { // standard block $item = $rs[$i]; } else { if (isset($rs[$i]->_object_type) && $rs[$i]->_object_type == "block_group_block_type") { // block type definition (mainly used to add a title before a list of blocks of the same type) $item = $rs[$i]; } else { if (isset($rs[$i]->extension)) { // extension block $item = block::extension_block($rs[$i]->extension, $rs[$i]->id); $item->type = "extension"; $item->extension = $rs[$i]->extension; $item->uid = $rs[$i]->uid; } else { // block from block group $item = new block(); $item->load_from_block_group($vars['type'], $rs[$i]->id, $rs[$i]->uid); } } } } else { if ($vars['source'] == 'gallery') { $item = $rs[$i]; } else { $item = new item(); $item->load($rs[$i]->id); // if the item comes from a custom source, save the original query result // this allows getting a special field without extra work ;) $item->_query = $rs[$i]; } } } } } // get the nv list template $item_html = $vars['template']; // first we need to isolate the nested nv lists/searches unset($nested_lists_fragments); list($item_html, $nested_lists_fragments) = nvweb_list_isolate_lists($item_html); // now, parse the nvlist_conditional tags (with html source code inside (and other nvlist tags)) unset($nested_condition_fragments); list($item_html, $nested_conditional_fragments) = nvweb_list_isolate_conditionals($item_html); $conditional_placeholder_tags = nvweb_tags_extract($item_html, 'nvlist_conditional_placeholder', true, true, 'UTF-8'); // selfclosing = true while (!empty($conditional_placeholder_tags)) { $tag = $conditional_placeholder_tags[0]; $conditional = $nested_conditional_fragments[$tag["attributes"]["id"]]; $conditional_html_output = nvweb_list_parse_conditional($conditional, $item, $conditional['nvlist_conditional_template'], $i, count($rs)); $item_html = str_replace($tag["full_tag"], $conditional_html_output, $item_html); $conditional_placeholder_tags = nvweb_tags_extract($item_html, 'nvlist_conditional_placeholder', true, true, 'UTF-8'); // selfclosing = true } // now, parse the (remaining) common nvlist tags (selfclosing tags) $template_tags_processed = 0; $template_tags = nvweb_tags_extract($item_html, 'nvlist', true, true, 'UTF-8'); // selfclosing = true while (!empty($template_tags)) { $tag = $template_tags[0]; // protect the "while" loop, maximum 500 nvlist tags parsed! $template_tags_processed++; if ($template_tags_processed > 500) { break; } $content = nvweb_list_parse_tag($tag, $item, $vars['source'], $i, $i + $offset, $total); $item_html = str_replace($tag['full_tag'], $content, $item_html); // html template has changed, the nvlist tags may have changed its positions $template_tags = nvweb_tags_extract($item_html, 'nvlist', true, true, 'UTF-8'); } // restore & process nested lists (if any) foreach ($nested_lists_fragments as $nested_list_uid => $nested_list_vars) { $nested_list_vars['nvlist_parent_vars'] = $vars; $nested_list_vars['nvlist_parent_type'] = $vars['source']; $nested_list_vars['nvlist_parent_item'] = $item; $content = nvweb_list($nested_list_vars); $item_html = str_replace('<!--#' . $nested_list_uid . '#-->', $content, $item_html); } $out[] = $item_html; } if (count($rs) == 0) { // special case, no results found // get the nv list template and parse only the conditional: <nvlist_conditional by="count" value="empty"> (or value=0) $item_html = $vars['template']; // now, parse the nvlist_conditional tags (with html source code inside (and other nvlist tags)) unset($nested_condition_fragments); list($item_html, $nested_conditional_fragments) = nvweb_list_isolate_conditionals($item_html); // remove all tags except (selfclosing) nvlist_conditional_placeholder $item_html = strip_tags($item_html, '<nvlist_conditional_placeholder>'); $conditional_placeholder_tags = nvweb_tags_extract($item_html, 'nvlist_conditional_placeholder', true, true, 'UTF-8'); // selfclosing=true while (!empty($conditional_placeholder_tags)) { $tag = $conditional_placeholder_tags[0]; $conditional = $nested_conditional_fragments[$tag["attributes"]["id"]]; $conditional_html_output = nvweb_list_parse_conditional($conditional, NULL, $conditional['nvlist_conditional_template'], $i, count($rs)); $item_html = str_replace($tag["full_tag"], $conditional_html_output, $item_html); $conditional_placeholder_tags = nvweb_tags_extract($item_html, 'nvlist_conditional_placeholder', true, true, 'UTF-8'); // selfclosing = true } $out[] = $item_html; } if (isset($vars['paginator']) && $vars['paginator'] != 'false') { $out[] = nvweb_list_paginator($vars['paginator'], $_GET['page'], $total, $vars['items'], $vars); } return implode("\n", $out); }
<?php require_once NAVIGATE_PATH . '/lib/external/force-utf8/Encoding.php'; nvweb_webget_load('content'); function nvweb_properties($vars = array()) { global $website; global $DB; global $current; global $cache; global $properties; global $webuser; $out = ''; switch (@$vars['mode']) { case 'website': $wproperty = new property(); $wproperty->load_from_theme($vars['property']); if (!empty($wproperty)) { $out = nvweb_properties_render($wproperty, $vars); } break; case 'webuser': $wuproperty = new property(); $wuproperty->load_from_webuser($vars['property']); if (!empty($wuproperty)) { $out = nvweb_properties_render($wuproperty, $vars); } break; case 'element': case 'item': // deprecated, may be removed in a future version
<?php nvweb_webget_load('menu'); 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'])) {