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_route_parse($route = "") { global $website; global $DB; global $current; global $session; global $theme; global $events; global $dictionary; // node route types if (substr($route, 0, 5) == 'node/') { $node = substr($route, 5); $route = 'node'; } switch ($route) { case 'object': nvweb_object(); nvweb_clean_exit(); break; case 'nvajax': nvweb_ajax(); nvweb_clean_exit(); break; case 'nvtags': case 'nvsearch': $current['template'] = 'search'; break; case 'nv.webuser/verify': $hash = $_REQUEST['hash']; $email = filter_var($_REQUEST['email'], FILTER_VALIDATE_EMAIL); if (!empty($hash) && !empty($email)) { $ok = webuser::email_verification($email, $hash); if ($ok) { $session['nv.webuser/verify:email_confirmed'] = time(); } } nvweb_clean_exit(NVWEB_ABSOLUTE . $website->homepage()); break; case 'node': if ($node > 0) { $current['id'] = $node; $DB->query('SELECT * FROM nv_items WHERE id = ' . protect($current['id']) . ' AND website = ' . $website->id); $current['object'] = $DB->first(); // let's count a hit (except admin) if ($current['navigate_session'] != 1 && !nvweb_is_bot()) { $DB->execute(' UPDATE nv_items SET views = views + 1 WHERE id = ' . $current['id'] . ' AND website = ' . $website->id); } $current['type'] = 'item'; $current['template'] = $current['object']->template; if ($current['navigate_session'] == 1 && !empty($_REQUEST['template'])) { $current['template'] = $_REQUEST['template']; } } break; case 'sitemap.xml': nvweb_webget_load('sitemap'); echo nvweb_sitemap(array('mode' => 'xml')); nvweb_clean_exit(); break; // redirect to home page of the current website // redirect to home page of the current website case 'nvweb.home': case 'nv.home': header('location: ' . NVWEB_ABSOLUTE . $website->homepage()); nvweb_clean_exit(); break; // webservice endpoint via XML-RPC calls // webservice endpoint via XML-RPC calls case 'xmlrpc': $events->trigger('nvweb', 'xmlrpc', array('route' => '/' . $route)); // if no extension processes the call, use the integrated XML-RPC parser nvweb_xmlrpc(); nvweb_clean_exit(); break; // empty path // empty path case '': case '/': case 'nv.empty': if ($website->empty_path_action == 'homepage_noredirect') { $route = $website->homepage(); if (strpos($route, '/') === 0) { $route = substr($route, 1); } } else { $route = ""; $website->wrong_path_action = $website->empty_path_action; } // do NOT break this case, continue processing as wrong_path action // no special route (or already processed), look for the path on navigate routing table // do NOT break this case, continue processing as wrong_path action // no special route (or already processed), look for the path on navigate routing table default: $DB->query('SELECT * FROM nv_paths WHERE path = ' . protect('/' . $route) . ' AND website = ' . $website->id . ' ORDER BY id DESC'); $rs = $DB->result(); if (empty($rs)) { // no valid route found switch ($website->wrong_path_action) { case 'homepage': case 'homepage_redirect': header('location: ' . NVWEB_ABSOLUTE . $website->homepage()); nvweb_clean_exit(); break; case 'http_404': header("HTTP/1.0 404 Not Found"); nvweb_clean_exit(); break; case 'theme_404': $current['template'] = 'not_found'; $current['type'] = 'structure'; $current['id'] = 0; $current['object'] = new structure(); return; break; case 'website_path': $redirect_url = nvweb_template_convert_nv_paths($website->wrong_path_redirect); header('location: ' . $redirect_url); nvweb_clean_exit(); break; case 'blank': default: nvweb_clean_exit(); break; } } else { // route found! // let's count a hit (except admin) if ($current['navigate_session'] != 1 && !nvweb_is_bot()) { $DB->execute(' UPDATE nv_paths SET views = views + 1 WHERE id = ' . $rs[0]->id . ' AND website = ' . $website->id); } // set the properties found // set the default language for this route if (!isset($_REQUEST['lang'])) { $current['lang'] = $rs[0]->lang; $session['lang'] = $rs[0]->lang; // force reloading the dictionary $dictionary = nvweb_dictionary_load(); } $current['type'] = $rs[0]->type; $current['id'] = $rs[0]->object_id; // look for the template associated with this item if ($current['type'] == 'structure') { $obj = new structure(); $obj->load($current['id']); // check if it is a direct access to a "jump to another branch" path if ($obj->dictionary[$current['lang']]['action-type'] == 'jump-branch') { $current['id'] = $obj->dictionary[$current['lang']]['action-jump-branch']; $obj = new structure(); $obj->load($current['id']); header('location: ' . NVWEB_ABSOLUTE . $obj->paths[$current['lang']]); nvweb_clean_exit(); } else { if ($obj->dictionary[$current['lang']]['action-type'] == 'jump-item') { $current['id'] = $obj->dictionary[$current['lang']]['action-jump-item']; $obj = new item(); $obj->load($current['id']); header('location: ' . NVWEB_ABSOLUTE . $obj->paths[$current['lang']]); nvweb_clean_exit(); } } $current['object'] = $obj; $current['category'] = $current['id']; if ($current['navigate_session'] != 1 && !nvweb_is_bot()) { $DB->execute(' UPDATE nv_structure SET views = views + 1 WHERE id = ' . protect($current['id']) . ' AND website = ' . $website->id); } } else { if ($current['type'] == 'item') { $DB->query('SELECT * FROM nv_items WHERE id = ' . protect($current['id']) . ' AND website = ' . $website->id); $current['object'] = $DB->first(); // let's count a hit (except admin) if ($current['navigate_session'] != 1 && !nvweb_is_bot()) { $DB->execute(' UPDATE nv_items SET views = views + 1 WHERE id = ' . $current['id'] . ' AND website = ' . $website->id); } } else { if ($current['type'] == 'feed') { $out = feed::generate_feed($current['id']); if ($current['navigate_session'] != 1 && !nvweb_is_bot()) { $DB->execute(' UPDATE nv_feeds SET views = views + 1 WHERE id = ' . $current['id'] . ' AND website = ' . $website->id); } echo $out; nvweb_clean_exit(); } else { // path exists, but the object type is unknown // maybe the path belongs to an extension? $events->trigger('nvweb', 'routes', array('path' => $rs[0])); } } } $current['template'] = $current['object']->template; } break; } }
public static function export_sample($a_categories, $a_items, $a_block_groups, $a_blocks, $a_comments, $folder) { global $website; global $theme; global $DB; @set_time_limit(0); $categories = array(); $items = array(); $blocks = array(); $block_groups = array(); $comments = array(); $properties = array(); $files = array(); $settings = array(); // structure for ($c = 0; $c < count($a_categories); $c++) { $tmp = new structure(); $tmp->load($a_categories[$c]); //$properties['structure'][$tmp->id] = property::load_properties_associative('structure', $tmp->template, 'structure', $tmp->id); $properties['structure'][$tmp->id] = property::load_properties('structure', $tmp->template, 'structure', $tmp->id); $categories[$tmp->id] = $tmp; // add files referenced in properties if (is_array($properties['structure'][$tmp->id])) { foreach ($properties['structure'][$tmp->id] as $property) { if ($property->type == 'image' || $property->type == 'file') { $files[] = $property->value; } } } } // comments for ($c = 0; $c < count($a_comments); $c++) { $tmp = new comment(); $tmp->load($a_comments[$c]); $comments[$tmp->id] = $tmp; } // items for ($i = 0; $i < count($a_items); $i++) { $tmp = new item(); $tmp->load($a_items[$i]); $template_id = $tmp->template; if ($tmp->association != "free" && $tmp->embedding == 1) { // we have to get the template set in the category of the item $template_id = $DB->query_single('template', 'nv_structure', ' id = ' . protect($tmp->category) . ' AND website = ' . $website->id); } $properties['item'][$tmp->id] = property::load_properties('item', $template_id, 'item', $tmp->id); list($tmp->dictionary, $files) = theme::export_sample_parse_dictionary($tmp->dictionary, $files); // add files referenced in properties if (is_array($properties['item'][$tmp->id])) { foreach ($properties['item'][$tmp->id] as $property) { if ($property->type == 'image' || $property->type == 'file') { $files[] = $property->value; } } } // add files referenced in gallery if (is_array($tmp->galleries[0])) { $gallery_images = array_keys($tmp->galleries[0]); $files = array_merge($files, $gallery_images); } $items[$tmp->id] = $tmp; } // block_groups for ($i = 0; $i < count($a_block_groups); $i++) { $tmp = new block_group(); $tmp->load($a_block_groups[$i]); $block_groups[$tmp->id] = $tmp; if (is_array($tmp->blocks)) { foreach ($tmp->blocks as $bgb) { if ($bgb['type'] == 'block_group_block') { $properties['block_group_block'][$a_block_groups[$i]][$bgb['uid']] = property::load_properties($bgb['id'], $tmp->code, 'block_group_block', $bgb['id'], $bgb['uid']); } else { if ($bgb['type'] == 'extension') { $properties['block_group_block'][$a_block_groups[$i]][$bgb['uid']] = property::load_properties(NULL, $bgb['id'], "extension_block", NULL, $bgb['uid']); } } } } // note: maybe not all blocks in the group have been selected in the "blocks" tab // here we only export the block group definition, the block group blocks properties and the extension blocks properties, not adding anything else to export } // blocks for ($i = 0; $i < count($a_blocks); $i++) { $tmp = new block(); $tmp->load($a_blocks[$i]); $properties['block'][$tmp->id] = property::load_properties('block', $tmp->type, 'block', $tmp->id); list($tmp->dictionary, $files) = theme::export_sample_parse_dictionary($tmp->dictionary, $files); list($tmp->trigger['trigger-content'], $files) = theme::export_sample_parse_array($tmp->trigger['trigger-content'], $files); list($tmp->trigger['trigger-html'], $files) = theme::export_sample_parse_array($tmp->trigger['trigger-html'], $files); if (!empty($tmp->trigger['trigger-image'])) { $files = array_merge($files, array_values($tmp->trigger['trigger-image'])); } if (!empty($tmp->trigger['trigger-rollover'])) { $files = array_merge($files, array_values($tmp->trigger['trigger-rollover'])); } if (!empty($tmp->trigger['trigger-rollover-active'])) { $files = array_merge($files, array_values($tmp->trigger['trigger-rollover-active'])); } if (!empty($tmp->trigger['trigger-flash'])) { $files = array_merge($files, array_values($tmp->trigger['trigger-flash'])); } if (!empty($tmp->action['action-image'])) { $files = array_merge($files, array_values($tmp->action['action-image'])); } if (!empty($tmp->action['action-file'])) { $files = array_merge($files, array_values($tmp->action['action-file'])); } // add files referenced in properties if (is_array($properties['block'][$tmp->id])) { foreach ($properties['block'][$tmp->id] as $property) { if ($property->type == 'image' || $property->type == 'file') { $files[] = $property->value; } } } $blocks[$tmp->id] = $tmp; } // folders // save references and get their files list $folders = array(); $folders_to_check = array(); if (!empty($folder)) { array_push($folders_to_check, $folder); while (!empty($folders_to_check)) { $f = array_shift($folders_to_check); $f = file::filesOnPath($f); foreach ($f as $file) { if ($file->type == 'folder') { array_push($folders_to_check, $file->id); array_push($folders, $file); } else { $files[] = $file->id; } } } } // add files selected as theme_options foreach ($theme->options as $to) { if ($to->type == 'image' || $to->type == 'file') { $to_value = $website->theme_options->{$to->id}; if (is_array($to_value)) { $files = array_merge($files, $to_value); } else { $files[] = $to_value; } } } // include favicon in file list if (!empty($website->favicon)) { $files[] = $website->favicon; } // files $files = array_unique($files); for ($f = 0; $f < count($files); $f++) { $file = new file(); $file->load($files[$f]); $files[$f] = $file; } // settings $settings['homepage'] = $website->homepage; $settings['favicon'] = $website->favicon; $zip = new zipfile(); $zip->addFile(var_export($website->languages, true), 'languages.var_export'); $zip->addFile(var_export($website->theme_options, true), 'theme_options.var_export'); $zip->addFile(var_export($categories, true), 'structure.var_export'); $zip->addFile(var_export($items, true), 'items.var_export'); $zip->addFile(var_export($block_groups, true), 'block_groups.var_export'); $zip->addFile(var_export($blocks, true), 'blocks.var_export'); $zip->addFile(var_export($comments, true), 'comments.var_export'); $zip->addFile(var_export($files, true), 'files.var_export'); $zip->addFile(var_export($folders, true), 'folders.var_export'); $zip->addFile(var_export($properties, true), 'properties.var_export'); $zip->addFile(var_export($settings, true), 'settings.var_export'); foreach ($files as $file) { $zip->addFile(file_get_contents($file->absolute_path()), 'files/' . $file->id); } $contents = $zip->file(); header('Content-Disposition: attachment; filename="' . $website->theme . '_sample.zip"'); header("Content-type: application/octet-stream"); header('Content-Length: ' . strlen($contents)); echo $contents; }
function run() { global $layout; global $DB; global $website; global $theme; global $user; $out = ''; $item = new item(); switch ($_REQUEST['act']) { case 'json': case 1: // json data retrieval & operations switch ($_REQUEST['oper']) { case 'del': // remove rows $ids = $_REQUEST['ids']; foreach ($ids as $id) { $item->load($id); $item->delete(); } echo json_encode(true); break; default: // list or search // translation of request search & order fields switch ($_REQUEST['searchField']) { case 'id': $_REQUEST['searchField'] = 'i.id'; break; case 'title': $_REQUEST['searchField'] = 'd.text'; break; case 'language': $_REQUEST['searchField'] = 'd.lang'; break; case 'category': $_REQUEST['searchField'] = 'i.category'; break; case 'dates': $_REQUEST['searchField'] = 'i.date_published'; break; case 'permission': $_REQUEST['searchField'] = 'i.permission'; break; default: } if ($_REQUEST['sidx'] == 'dates') { $_REQUEST['sidx'] = 'i.date_published'; } $page = intval($_REQUEST['page']); $max = intval($_REQUEST['rows']); $offset = ($page - 1) * $max; $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord']; $where = ' i.website = ' . $website->id; if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) { if (isset($_REQUEST['quicksearch'])) { $where .= $item->quicksearch($_REQUEST['quicksearch']); } else { if (isset($_REQUEST['filters'])) { if (is_array($_REQUEST['filters'])) { $filters = json_decode(json_encode($_REQUEST['filters']), FALSE); } else { $filters = json_decode($_REQUEST['filters']); } for ($r = 0; $r < count($filters->rules); $r++) { switch ($filters->rules[$r]->field) { case 'id': $filters->rules[$r]->field = 'i.id'; break; case 'title': $filters->rules[$r]->field = 'd.text'; break; case 'language': $filters->rules[$r]->field = 'd.lang'; break; case 'category': $filters->rules[$r]->field = 'i.category'; break; case 'dates': $filters->rules[$r]->field = 'i.date_published'; break; case 'permission': $filters->rules[$r]->field = 'i.permission'; break; default: } } $where .= navitable::jqgridsearch(json_encode($filters)); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } $sql = ' SELECT SQL_CALC_FOUND_ROWS i.*, d.text as title, d.lang as language, u.username as author_username, ( SELECT COUNT(*) FROM nv_comments cm WHERE cm.item = i.id AND cm.website = ' . $website->id . ' ) as comments FROM nv_items i LEFT JOIN nv_webdictionary d ON i.id = d.node_id AND d.node_type = "item" AND d.subtype = "title" AND d.lang = "' . $website->languages_list[0] . '" AND d.website = ' . $website->id . ' LEFT JOIN nv_users u ON u.id = i.author WHERE ' . $where . ' GROUP BY i.id, d.text, d.lang, u.username ORDER BY ' . $orderby . ' LIMIT ' . $max . ' OFFSET ' . $offset; if (!$DB->query($sql, 'array')) { throw new Exception($DB->get_last_error()); } $dataset = $DB->result(); $total = $DB->foundRows(); $dataset = grid_notes::summary($dataset, 'item', 'id'); $access = array(0 => '<img src="img/icons/silk/page_white_go.png" align="absmiddle" title="' . t(254, 'Everybody') . '" />', 1 => '<img src="img/icons/silk/lock.png" align="absmiddle" title="' . t(361, 'Web users only') . '" />', 2 => '<img src="img/icons/silk/user_gray.png" align="absmiddle" title="' . t(363, 'Users who have not yet signed up or signed in') . '" />', 3 => '<img src="img/icons/silk/group_key.png" align="absmiddle" title="' . t(512, "Selected web user groups") . '" />'); $permissions = array(0 => '<img src="img/icons/silk/world.png" align="absmiddle" /> ' . t(69, 'Published'), 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" /> ' . t(70, 'Private'), 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" /> ' . t(81, 'Hidden')); $hierarchy = structure::hierarchy(0); // we need to format the values and retrieve the needed strings from the dictionary $out = array(); for ($i = 0; $i < count($dataset); $i++) { if (empty($dataset[$i])) { continue; } if (empty($dataset[$i]['date_published'])) { $dataset[$i]['date_published'] = '∞'; } else { $dataset[$i]['date_published'] = core_ts2date($dataset[$i]['date_published'], false); } if (empty($dataset[$i]['date_unpublish'])) { $dataset[$i]['date_unpublish'] = '∞'; } else { $dataset[$i]['date_unpublish'] = core_ts2date($dataset[$i]['date_unpublish'], false); } if (empty($dataset[$i]['date_to_display'])) { $dataset[$i]['date_to_display'] = ''; } else { $dataset[$i]['date_to_display'] = core_ts2date($dataset[$i]['date_to_display'], false); } if ($dataset[$i]['category'] > 0) { $category_path = structure::hierarchyPath($hierarchy, $dataset[$i]['category']); if (is_array($category_path)) { $dataset[$i]['category_path'] = implode(' › ', $category_path); } else { $dataset[$i]['category_path'] = $category_path; } } $category_text = ''; if ($dataset[$i]['association'] == 'free') { $category_text = '[ ' . strtolower(t(100, 'Free')) . ' ]'; } else { $category_text = $dataset[$i]['category_path']; } $item_views = $dataset[$i]['views']; if ($item_views > 1000) { $item_views = round($item_views / 1000) . "K"; } $item_comments = $dataset[$i]['comments']; if ($item_comments > 1000) { $item_comments = round($item_comments / 1000) . "K"; } //$social_rating = '<img src="img/icons/silk/star.png" align="absmiddle" width="12px" height="12px" /> '. // '<span style="font-size: 90%;">'.$dataset[$i]['score'].' ('.$dataset[$i]['votes'].')</span>'; //$social_rating = '<i class="fa fa-fw fa-eye" /> <span style="font-size: 90%;">'.$dataset[$i]['views'].'</span>'; $social_rating = '<img src="img/icons/silk/eye.png" align="absmiddle" width="12px" height="12px" /> ' . '<span style="font-size: 90%;">' . $item_views . '</span>'; //$social_comments = '<i class="fa fa-fw fa-comments-o" /> <span style="font-size: 90%;">'.$dataset[$i]['comments'].'</span>'; $social_comments = '<img src="img/icons/silk/comments.png" align="absmiddle" width="12px" height="12px" /> ' . '<span style="font-size: 90%;">' . $item_comments . '</span>'; if (empty($dataset[$i]['title'])) { // if title is empty for the default language, // try to load the title in another language $DB->query(' SELECT lang, text FROM nv_webdictionary WHERE website = ' . $website->id . ' AND node_type = "item" AND subtype="title" AND node_id = ' . $dataset[$i]['id'] . ' AND text != "" ORDER BY id ASC'); $titles = $DB->result(); if (!empty($titles)) { $dataset[$i]['title'] = '<img src="img/icons/silk/comment.png" align="absmiddle" />'; $dataset[$i]['title'] .= '<small>' . $titles[0]->lang . '</small> '; $dataset[$i]['title'] .= $titles[0]->text; } } $out[$i] = array(0 => $dataset[$i]['id'], 1 => '<div class="list-row" data-permission="' . $dataset[$i]['permission'] . '">' . $dataset[$i]['title'] . '</div>', 2 => $social_rating . ' ' . $social_comments, 3 => $category_text, 4 => $dataset[$i]['date_to_display'], 5 => $dataset[$i]['date_published'] . ' - ' . $dataset[$i]['date_unpublish'], 6 => $access[$dataset[$i]['access']] . ' ' . $permissions[$dataset[$i]['permission']], 7 => $dataset[$i]['_grid_notes_html']); } navitable::jqgridJson($out, $page, $offset, $max, $total); break; } core_terminate(); break; case 'load': case 'create': case 'edit': case 2: // edit/new form if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); if ($user->permission("items.edit") == "false" && $item->author != $user->id) { $layout->navigate_notification(t(610, "Sorry, you are not allowed to execute the requested function"), true); $_REQUEST['act'] = 'list'; return run(); } // check if the current user can edit this item if ($item->association == 'category' && !empty($item->category)) { if (!structure::category_allowed($item->category)) { $layout->navigate_notification(t(610, "Sorry, you are not allowed to execute the requested function"), true); $_REQUEST['act'] = 'list'; return run(); } } } if (isset($_REQUEST['form-sent'])) { $item->load_from_post(); try { $item->save(); property::save_properties_from_post('item', $item->id); if (!empty($_REQUEST['items-order'])) { item::reorder($_REQUEST['items-order']); } $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); $item->load($item->id); users_log::action($_REQUEST['fid'], $item->id, 'save', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST)); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } } else { users_log::action($_REQUEST['fid'], $item->id, 'load', $item->dictionary[$website->languages_list[0]]['title']); } $out = items_form($item); break; case 'delete': case 4: // remove if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); try { if (!empty($item->id)) { $deleted = $item->delete() > 0; if ($deleted) { $layout->navigate_notification(t(55, 'Item removed successfully.'), false); $out = items_list(); users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST)); } } if (!$deleted) { $layout->navigate_notification(t(56, 'Unexpected error.'), false); if (!empty($item->id)) { $out = items_form($item); } else { $out = items_list(); } } } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true); if (!empty($item->id)) { $out = items_form($item); } } } break; case 'duplicate': if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); if ($item->association == 'category' && $item->embedding == 1) { // get structure template $category = new structure(); $category->load($item->category); $properties = property::load_properties_associative('structure', $category->template, 'item', $item->id); } else { $properties = property::load_properties_associative('item', $item->template, 'item', $item->id); } // try to duplicate $item->id = 0; $ok = $item->insert(); if ($ok) { // duplicate item properties too (but don't duplicate comments) if ($item->association == 'category' && $item->embedding == 1) { $ok = property::save_properties_from_array('item', $item->id, $category->template, $properties); } else { $ok = property::save_properties_from_array('item', $item->id, $item->template, $properties); } } if ($ok) { $layout->navigate_notification(t(478, 'Item duplicated successfully.'), false, false, 'fa fa-check'); $out = items_form($item); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $item = new item(); $item->load(intval($_REQUEST['id'])); $out = items_form($item); } users_log::action($_REQUEST['fid'], $item->id, 'duplicate', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST)); } break; case 89: if (!empty($_REQUEST['id'])) { $DB->execute('DELETE FROM nv_webdictionary_history WHERE id = ' . intval($_REQUEST['id']) . ' LIMIT 1'); echo 'true'; } else { echo 'false'; } core_terminate(); break; case 90: $DB->query('SELECT id, date_created, autosave FROM nv_webdictionary_history WHERE node_type = "item" AND subtype = ' . protect('section-' . $_REQUEST['section']) . ' AND lang = ' . protect($_GET['lang']) . ' AND node_id = ' . protect($_REQUEST['id']) . ' AND website = ' . $website->id . ' ORDER BY date_created DESC', 'array'); $result = $DB->result(); if (!is_array($result)) { $result = array(); } for ($i = 0; $i < count($result); $i++) { $result[$i]['date'] = core_ts2date($result[$i]['date_created'], true); if ($result[$i]['autosave'] == 1) { $result[$i]['date'] .= ' (' . t(273, 'Autosave') . ')'; } } echo json_encode($result); core_terminate(); break; case "search_by_title": case 91: // json search title request (for "copy from" dialog) $DB->query(' SELECT node_id as id, text as label, text as value FROM nv_webdictionary WHERE node_type = "item" AND subtype = "title" AND lang = ' . protect($_REQUEST['lang']) . ' AND website = ' . $website->id . ' AND text LIKE ' . protect('%' . $_REQUEST['title'] . '%') . ' ORDER BY text ASC LIMIT 20', 'array'); echo json_encode($DB->result()); core_terminate(); break; case "raw_zone_content": // return raw item contents if (empty($_REQUEST['section'])) { $_REQUEST['section'] = 'main'; } if ($_REQUEST['history'] == 'true') { $DB->query('SELECT text FROM nv_webdictionary_history WHERE node_type = "item" AND website = ' . $website->id . ' AND id = ' . protect($_REQUEST['id']), 'array'); $data = $DB->first(); echo $data['text']; } else { if ($_REQUEST['zone'] == 'section') { $DB->query('SELECT text FROM nv_webdictionary WHERE node_type = "item" AND subtype = ' . protect('section-' . $_REQUEST['section']) . ' AND lang = ' . protect($_REQUEST['lang']) . ' AND website = ' . $website->id . ' AND node_id = ' . protect($_REQUEST['node_id']), 'array'); $data = $DB->first(); echo $data['text']; } else { if ($_REQUEST['zone'] == 'property') { $DB->query('SELECT text FROM nv_webdictionary WHERE node_type = "property-item" AND subtype = ' . protect('property-' . $_REQUEST['section'] . '-' . $_REQUEST['lang']) . ' AND lang = ' . protect($_REQUEST['lang']) . ' AND website = ' . $website->id . ' AND node_id = ' . protect($_REQUEST['node_id']), 'array'); $data = $DB->first(); echo $data['text']; } } } core_terminate(); break; // return raw template content // return raw template content case 93: $DB->query('SELECT file FROM nv_templates WHERE enabled = 1 AND id = ' . protect($_REQUEST['id']) . ' AND website = ' . $website->id, 'array'); $data = $DB->first(); echo @file_get_contents(NAVIGATE_PRIVATE . '/' . $website->id . '/templates/' . $data['file']); core_terminate(); break; case "copy_from_template_zones": // return template sections and (textarea) properties for a content id $item = new item(); $item->load(intval($_REQUEST['id'])); $template = $item->load_template(); $zones = array(); for ($ts = 0; $ts < count($template->sections); $ts++) { $title = $template->sections[$ts]['name']; if (!empty($theme)) { $title = $theme->t($title); } if ($title == '#main#') { $title = t(238, 'Main content'); } $zones[] = array('type' => 'section', 'id' => $template->sections[$ts]['id'], 'title' => $title); } for ($ps = 0; $ps < count($template->properties); $ps++) { // ignore structure properties if (isset($template->properties[$ps]->element) && $template->properties[$ps]->element != 'item') { continue; } // ignore non-textual properties if (!in_array($template->properties[$ps]->type, array("text", "textarea", "rich_textarea"))) { continue; } $title = $template->properties[$ps]->name; if (!empty($theme)) { $title = $theme->t($title); } $zones[] = array('type' => 'property', 'id' => $template->properties[$ps]->id, 'title' => $title); } echo json_encode($zones); core_terminate(); break; case 95: // free path checking $path = $_REQUEST['path']; $id = $_REQUEST['id']; $DB->query('SELECT type, object_id, lang FROM nv_paths WHERE path = ' . protect($path) . ' AND website = ' . $website->id); $rs = $DB->result(); echo json_encode($rs); core_terminate(); break; case 96: // return category paths echo json_encode(path::loadElementPaths('structure', intval($_REQUEST['id']))); core_terminate(); break; case 'json_find_user': // json find user by name request (for "moderator" autocomplete) $DB->query(' SELECT id, username as text FROM nv_users WHERE username LIKE ' . protect('%' . $_REQUEST['username'] . '%') . ' ORDER BY username ASC LIMIT 30', 'array '); $rows = $DB->result(); $total = $DB->foundRows(); echo json_encode(array('items' => $rows, 'total_count' => $total)); core_terminate(); break; case 'json_find_item': // find items by its title // any language $template_filter = ''; if (!empty($_REQUEST['template'])) { $template_filter = ' AND nvi.template = ' . protect($_REQUEST['template']) . ' '; } if (!empty($_REQUEST['association'])) { $template_filter = ' AND nvi.association = ' . protect($_REQUEST['association']) . ' '; } if (isset($_REQUEST['embedding'])) { $template_filter = ' AND nvi.embedding = ' . protect($_REQUEST['embedding']) . ' '; } $text = $_REQUEST['title']; if (!empty($_REQUEST['term'])) { // tagit request $text = $_REQUEST['term']; } $DB->query(' SELECT SQL_CALC_FOUND_ROWS DISTINCT nvw.node_id as id, nvw.text as text FROM nv_webdictionary nvw, nv_items nvi WHERE nvw.node_type = "item" AND nvw.node_id = nvi.id ' . $template_filter . ' AND nvw.subtype = "title" AND nvw.website = ' . $website->id . ' AND nvw.website = nvi.website AND nvw.text LIKE ' . protect('%' . $text . '%') . ' GROUP BY nvw.node_id, nvw.text ORDER BY nvw.text ASC LIMIT ' . intval($_REQUEST['page_limit']) . ' OFFSET ' . max(0, intval($_REQUEST['page_limit']) * (intval($_REQUEST['page']) - 1)), 'array'); $rows = $DB->result(); $total = $DB->foundRows(); if ($_REQUEST['association'] == 'free') { for ($i = 0; $i < count($rows); $i++) { $rows[$i]['path'] = $DB->query_single('path', 'nv_paths', ' website = ' . protect($website->id) . ' AND type="item" AND object_id="' . $rows[$i]['id'] . '" AND lang="' . $website->languages_list[0] . '" '); if (empty($rows[$i]['path'])) { $rows[$i]['path'] = '/node/' . $rows[$i]['id']; } } } if (empty($_REQUEST['format']) || $_REQUEST['format'] == 'select2') { echo json_encode(array('items' => $rows, 'totalCount' => $total)); } else { if ($_REQUEST['format'] == 'tagit') { $tags_json = array(); foreach ($rows as $row) { $tags_json[] = json_decode('{ "id": "' . $row['id'] . '", "label": "' . $row['text'] . '", "value": "' . $row['text'] . '" }'); } echo json_encode($tags_json); } } core_terminate(); break; case 98: // change comment status if (empty($_REQUEST['id'])) { echo "false"; core_terminate(); } switch ($_REQUEST['opt']) { case 'publish': $DB->execute(' UPDATE nv_comments SET status = 0 WHERE website = ' . $website->id . ' AND id = ' . $_REQUEST['id']); break; case 'unpublish': $DB->execute(' UPDATE nv_comments SET status = 1 WHERE website = ' . $website->id . ' AND id = ' . $_REQUEST['id']); break; case 'delete': $DB->execute(' DELETE FROM nv_comments WHERE website = ' . $website->id . ' AND id = ' . $_REQUEST['id']); break; } $error = $DB->get_last_error(); if (empty($error)) { echo 'true'; } else { echo 'false'; } core_terminate(); break; case 'autosave': if (!empty($_REQUEST['id'])) { $iDictionary = array(); foreach ($_REQUEST as $key => $value) { if (strpos($key, 'section-') === 0) { $lang = substr($key, -2, 2); $kname = substr($key, 0, strlen($key) - 3); $iDictionary[$lang][$kname] = $value; } } $changed = webdictionary_history::save_element_strings('item', intval($_REQUEST['id']), $iDictionary, true); if ($changed) { echo 'changes_saved'; } else { echo 'no_changes'; } core_terminate(); } echo 'false'; core_terminate(); break; case 'votes_reset': webuser_vote::remove_object_votes('item', intval($_REQUEST['id'])); echo 'true'; core_terminate(); break; case 'votes_by_webuser': if ($_POST['oper'] == 'del') { $ids = explode(',', $_POST['id']); for ($i = 0; $i < count($ids); $i++) { if ($ids[$i] > 0) { $vote = new webuser_vote(); $vote->load($ids[$i]); $vote->delete(); } } webuser_vote::update_object_score('item', $vote->object_id); echo 'true'; core_terminate(); } $max = intval($_GET['rows']); $page = intval($_GET['page']); $offset = ($page - 1) * $max; if ($_REQUEST['_search'] == 'false') { list($dataset, $total) = webuser_vote::object_votes_by_webuser('item', intval($_REQUEST['id']), $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'], $offset, $max); } $out = array(); for ($i = 0; $i < count($dataset); $i++) { if (empty($dataset[$i])) { continue; } $out[$i] = array(0 => $dataset[$i]['id'], 1 => core_ts2date($dataset[$i]['date'], true), 2 => $dataset[$i]['username']); } navitable::jqgridJson($out, $page, $offset, $max, $total); core_terminate(); break; case 'items_order': if (!empty($_POST['items-order'])) { // save new order $response = item::reorder($_POST['items-order']); if ($response !== true) { echo $response['error']; } else { echo 'true'; } } else { // show ordered list echo items_order($_REQUEST['category']); } core_terminate(); break; case 'json_tags_search': $tags = nvweb_tags_retrieve(null, null, 'top', $_REQUEST['term'], $_REQUEST['lang']); $tags_json = array(); foreach (array_keys($tags) as $tag) { $tags_json[] = json_decode('{ "id": "' . $tag . '", "label": "' . $tag . '", "value": "' . $tag . '" }'); } echo json_encode($tags_json); core_terminate(); break; case 'json_tags_ranking': $tags = nvweb_tags_retrieve(100, null, 'top', null, $_REQUEST['lang']); $tags = array_keys($tags); echo json_encode($tags); core_terminate(); break; case 'list': case 0: // list / search result // list / search result default: $out = items_list(); break; } return $out; }
function nvweb_gallery($vars = array()) { global $website; global $DB; global $current; global $webgets; $out = ''; $webget = 'gallery'; // the request can come from a free item or from a category, so we have to load the first element available $item = NULL; $border = ''; if (!empty($vars['border'])) { $border = '&border=' . $vars['border']; } $items = PHP_INT_MAX; // number of images shown, 0 => all gallery photos if (!empty($vars['items']) && $vars['items'] != '0') { $items = intval($vars['items']); } $order = 'priority'; // display images using the assigned priority if (!empty($vars['order'])) { $order = $vars['order']; } if (!empty($vars['item'])) { if (is_object($vars['item'])) { $item = $vars['item']; } else { if (is_numeric($vars['item'])) { $item = new item(); $item->load($vars['item']); } } } else { if ($current['type'] == 'item') { // check publishing is enabled $enabled = nvweb_object_enabled($current['object']); if ($enabled || $_REQUEST['preview'] == 'true' && $current['navigate_session'] == 1) { $item = $current['object']; } } else { if ($current['type'] == 'structure') { $DB->query(' SELECT id, permission, date_published, date_unpublish FROM nv_items WHERE category = ' . protect($current['object']->id) . ' AND website = ' . $website->id . ' '); $rs = $DB->first(); $enabled = nvweb_object_enabled($rs); if ($enabled || $_REQUEST['preview'] == 'true' && $current['navigate_session'] == 1) { $item = new item(); $item->load($rs->id); } } } } if ($item == NULL) { return ''; } if (empty($vars['width']) && empty($vars['height'])) { $vars['width'] = 120; $vars['height'] = 90; } else { if (empty($vars['height'])) { $vars['height'] = ''; } else { if (empty($vars['width'])) { $vars['width'] = ''; } } } // which gallery model? $out = array(); switch (@$vars['mode']) { case 'image': if (is_array($item->galleries)) { $gallery = $item->galleries[0]; } if (is_string($item->galleries)) { $gallery = mb_unserialize($item->galleries); $gallery = $gallery[0]; } // no images in the gallery? if (!is_array($gallery)) { return ''; } $gallery = nvweb_gallery_reorder($gallery, $order); $image_ids = array_keys($gallery); $position = intval($vars['position']); $image_selected = $image_ids[$position]; // no image found at the requested position if (empty($image_selected)) { return ''; } list($image_title, $image_description) = nvweb_gallery_image_caption($image_selected, $gallery); if (!empty($vars['return']) && $vars['return'] == 'url') { $out[] = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image_selected . '&disposition=inline'; } else { if (!empty($vars['return']) && $vars['return'] == 'thumbnail') { $out[] = '<img src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image_selected . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" />'; } else { if (!empty($vars['return']) && $vars['return'] == 'thumbnail_url') { $out[] = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image_selected . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border; } else { $out[] = '<div class="nv_gallery_item"> <a class="nv_gallery_a" href="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image_selected . '&disposition=inline" rel="gallery[item-' . $item->id . ']"> <img class="nv_gallery_image" src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image_selected . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" /> </a> </div>'; } } } break; case 'greybox': /* var image_set = [{'caption': 'Flower', 'url': 'http://static.flickr.com/119/294309231_a3d2a339b9.jpg'}, {'caption': 'Nice waterfall', 'url': 'http://www.widerange.org/images/large/plitvicka.jpg'}]; */ $out[] = '<div class="nv_gallery">'; $gallery = mb_unserialize($item->galleries); $gallery = $gallery[0]; $gallery = nvweb_gallery_reorder($gallery, $order); $first = true; $jsout = "var image_set_" . $item->id . " = ["; $preload = array(); foreach ($gallery as $image => $dictionary) { list($image_title, $image_description) = nvweb_gallery_image_caption($image, $gallery); if ($first) { $out[] = '<a href="#" onclick="return GB_showImageSet(image_set_' . $item->id . ', 1);"> <img class="nv_gallery_image" src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" /> </a>'; } if (!$first) { $jsout .= ',' . "\n"; } $jsout .= '{"caption": "' . $image_title . '", "url": "' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline"}'; $preload[] = "'" . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline'; $first = false; $items--; if ($items <= 0) { break; } } $jsout .= "];"; nvweb_after_body('js', $jsout); nvweb_after_body('js', 'AJS.preloadImages(' . implode(',', $preload) . ')'); $out[] = '<div style=" clear: both; "></div>'; $out[] = '</div>'; break; case 'piecemaker': $gallery = mb_unserialize($item->galleries); $gallery = nvweb_gallery_reorder($gallery[0], $order); foreach ($gallery as $image => $dictionary) { list($image_title, $image_description) = nvweb_gallery_image_caption($image, $gallery); $out[] = '<Image Source="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" Title="' . $image_title . '"></Image>'; $items--; if ($items <= 0) { break; } } break; case 'images': // plain IMG without links or divs // TO DO: add alt and title to the image if (is_array($item->galleries)) { $gallery = $item->galleries[0]; } if (is_string($item->galleries)) { $gallery = mb_unserialize($item->galleries); $gallery = $gallery[0]; } $gallery = nvweb_gallery_reorder($gallery, $order); $images = array_keys($gallery); if (empty($images)) { return ''; } foreach ($images as $img) { list($image_title, $image_description) = nvweb_gallery_image_caption($img, $gallery); $out[] = '<img class="nv_gallery_image" src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $img . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" />'; $items--; if ($items <= 0) { break; } } break; case 'image_links': // IMG wrapped by a link // TO DO: add alt and title to the image if (is_array($item->galleries)) { $gallery = $item->galleries[0]; } if (is_string($item->galleries)) { $gallery = mb_unserialize($item->galleries); $gallery = $gallery[0]; } $gallery = nvweb_gallery_reorder($gallery, $order); $images = array_keys($gallery); if (empty($images)) { return ''; } foreach ($images as $img) { list($image_title, $image_description) = nvweb_gallery_image_caption($img, $gallery); $out[] = ' <a class="nv_gallery_a" href="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $img . '&disposition=inline"> <img class="nv_gallery_image" src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $img . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" /> </a>'; $items--; if ($items <= 0) { break; } } break; case 'prettyphoto': case 'prettyPhoto': default: $out[] = '<div class="nv_gallery">'; if (is_array($item->galleries)) { $gallery = $item->galleries[0]; } if (is_string($item->galleries)) { $gallery = mb_unserialize($item->galleries); $gallery = $gallery[0]; } $gallery = nvweb_gallery_reorder($gallery, $order); $first = true; foreach ($gallery as $image => $dictionary) { if ($vars['only_first'] == 'true') { $style = ' style="display: none;" '; if ($first) { $style = ' style="display: block;" '; } $first = false; } list($image_title, $image_description) = nvweb_gallery_image_caption($img, $gallery); $out[] = '<div class="nv_gallery_item" ' . $style . '> <a class="nv_gallery_a" href="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline" rel="gallery[item-' . $item->id . ']"> <img class="nv_gallery_image" src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" /> </a> </div>'; $items--; if ($items <= 0) { break; } } $out[] = '<div style=" clear: both; "></div>'; $out[] = '</div>'; break; } $out = implode("\n", $out); return $out; }
function blocks_form($item) { global $user; global $DB; global $website; global $layout; global $events; global $theme; $current_version = $_SESSION['current_version']; $navibars = new navibars(); $naviforms = new naviforms(); $layout->navigate_media_browser(); // we can use media browser in this function if (empty($item->id)) { $navibars->title(t(23, 'Blocks') . ' / ' . t(38, 'Create')); } else { $navibars->title(t(23, 'Blocks') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']'); } $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();" title="Ctrl+M"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . ' </a>')); $layout->add_script("\r\n \$(document).on('keydown.ctrl_s', function (evt) { navigate_tabform_submit(1); return false; } );\r\n \$(document).on('keydown.ctrl_m', function (evt) { navigate_media_browser(); return false; } );\r\n "); if (!empty($item->id)) { $notes = grid_notes::comments('block', $item->id); $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_display_notes_dialog();"><span class="navigate_grid_notes_span" style=" width: 20px; line-height: 16px; ">' . count($notes) . '</span><img src="img/skins/badge.png" width="20px" height="18px" style="margin-top: -2px;" class="grid_note_edit" align="absmiddle" /> ' . t(168, 'Notes') . '</a>')); } if (empty($item->id)) { $navibars->add_actions(array($user->permission('blocks.create') == 'true' ? '<a href="#" onclick="navigate_tabform_submit(1);" title="Ctrl+S"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . ' </a>' : "")); } else { $navibars->add_actions(array($user->permission('blocks.edit') == 'true' ? '<a href="#" onclick="navigate_tabform_submit(1);" title="Ctrl+S"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . ' </a>' : "", $user->permission("blocks.delete") == 'true' ? '<a href="#" onclick="navigate_delete_dialog();"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . ' </a>' : "")); $layout->add_script(' function navigate_delete_dialog() { navigate_confirmation_dialog( function() { window.location.href = "?fid=blocks&act=delete&id=' . $item->id . '"; }, null, null, "' . t(35, 'Delete') . '" ); } '); } $group_blocks_links = array(); list($bg_rs, $bg_total) = block_group::paginated_list(0, 10, 'title', 'desc'); if ($bg_total > 0 && $bg_total <= 10) { foreach ($bg_rs as $bg) { $group_blocks_links[] = '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_group_edit&id=' . $bg['id'] . '"><i class="fa fa-fw fa-caret-right"></i> ' . $bg['title'] . '</a>'; } $events->add_actions('blocks', array('item' => null, 'navibars' => &$navibars), $group_blocks_links, '<a class="content-actions-submenu-trigger" href="?fid=' . $_REQUEST['fid'] . '&act=block_groups_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/bricks.png"> ' . t(506, 'Groups') . ' ▾</a>'); } $navibars->add_actions(array(!empty($group_blocks_links) ? '' : '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_groups_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/bricks.png"> ' . t(506, 'Groups') . '</a>', '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_types_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/brick_edit.png"> ' . t(167, 'Types') . '</a>')); $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=' . $_REQUEST['fid'] . '&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=' . $_REQUEST['fid'] . '&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>', 'search_form')); if (!empty($item->id)) { $layout->navigate_notes_dialog('block', $item->id); } $navibars->form(); $navibars->add_content(' <script type="text/javascript" src="lib/packages/blocks/blocks.js?r=' . $current_version->revision . '"></script> '); $navibars->add_tab(t(43, "Main")); $navibars->add_tab_content($naviforms->hidden('form-sent', 'true')); $navibars->add_tab_content($naviforms->hidden('id', $item->id)); $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . (!empty($item->id) ? $item->id : t(52, '(new)')) . '</span>')); $block_types = block::types(); $block_types_keys = array(); $block_types_info = array(); for ($i = 0; $i < count($block_types); $i++) { if ($item->type == $block_types[$i]['code']) { $block_type_width = $block_types[$i]['width']; } $block_size_helper = ''; if (!empty($block_types[$i]['width']) || !empty($block_types[$i]['height'])) { if (empty($block_types[$i]['width'])) { $block_types[$i]['width'] = '***'; } if (empty($block_types[$i]['height'])) { $block_types[$i]['height'] = '***'; } $block_size_helper = ' (' . $block_types[$i]['width'] . ' x ' . $block_types[$i]['height'] . ' px)'; } if (is_numeric($block_types[$i]['id'])) { $block_types_keys[] = $block_types[$i]['code']; } else { $block_types_keys[] = $block_types[$i]['id']; } // block described in theme definition $block_types_info[] = $block_types[$i]['title'] . $block_size_helper; } $navibars->add_tab_content_row(array('<label>' . t(160, 'Type') . '</label>', $naviforms->selectfield('type', $block_types_keys, $block_types_info, $item->type))); $navibars->add_tab_content_row(array('<label>' . t(85, 'Date published') . '</label>', $naviforms->datefield('date_published', $item->date_published, true))); $navibars->add_tab_content_row(array('<label>' . t(90, 'Date unpublished') . '</label>', $naviforms->datefield('date_unpublish', $item->date_unpublish, true))); // Notes field is deprecated, but we keep on showing the existing Notes if (!empty($item->notes)) { $navibars->add_tab_content_row(array('<label>' . t(168, 'Notes') . '</label>', $naviforms->textarea('notes', $item->notes))); } $navibars->add_tab_content_row(array('<label>' . t(364, 'Access') . '</label>', $naviforms->selectfield('access', array(0 => 0, 1 => 2, 2 => 1, 3 => 3), array(0 => t(254, 'Everybody'), 1 => t(362, 'Not signed in'), 2 => t(361, 'Web users only'), 3 => t(512, 'Selected web user groups')), $item->access, 'navigate_webuser_groups_visibility($(this).val());', false, array(1 => t(363, 'Users who have not yet signed in'))))); $webuser_groups = webuser_group::all_in_array(); $navibars->add_tab_content_row(array('<label>' . t(506, "Groups") . '</label>', $naviforms->multiselect('groups', array_keys($webuser_groups), array_values($webuser_groups), $item->groups)), 'webuser-groups-field'); $layout->add_script(' function navigate_webuser_groups_visibility(access_value) { if(access_value==3) $("#webuser-groups-field").show(); else $("#webuser-groups-field").hide(); } navigate_webuser_groups_visibility(' . $item->access . '); '); if (empty($item->id)) { $item->enabled = true; } $navibars->add_tab_content_row(array('<label>' . t(65, 'Enabled') . '</label>', $naviforms->checkbox('enabled', $item->enabled))); if ($item->date_modified > 0) { $navibars->add_tab_content_row(array('<label>' . t(227, 'Date modified') . '</label>', core_ts2date($item->date_modified, true))); } $navibars->add_tab(t(9, "Content")); switch ($item->class) { case 'poll': $options = array(); foreach ($website->languages_list as $lang) { $options[$lang] = language::name_by_code($lang); } $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $options, $website->languages_list[0], "navigate_items_select_language(this);"))); foreach ($website->languages_list as $lang) { $navibars->add_tab_content(' <div class="language_fields" id="language_fields_' . $lang . '" style=" display: none; "> '); $navibars->add_tab_content_row(array('<label>' . t(558, 'Question') . '</label>', $naviforms->textfield('title-' . $lang, @$item->dictionary[$lang]['title']), '')); // Poll options $table = new naviorderedtable("poll_answers_table_" . $lang); $table->setWidth("330px"); $table->setHiddenInput("poll-answers-table-order-" . $lang); $navibars->add_tab_content($naviforms->hidden("poll-answers-table-order-" . $lang, "")); $table->addHeaderColumn(t(67, 'Title'), 200); //$table->addHeaderColumn(t(237, 'Code'), 120); $table->addHeaderColumn(t(352, 'Votes'), 80); $table->addHeaderColumn(t(35, 'Remove'), 50); if (!empty($item->trigger[$lang])) { $poll_answers = $item->trigger[$lang]; foreach ($poll_answers as $pa) { $uid = uniqid(); $table->addRow("poll-answers-table-row-" . $uid, array(array('content' => '<input type="text" name="poll-answers-table-title-' . $lang . '[' . $uid . ']" value="' . $pa['title'] . '" style="width: 200px;" />', 'align' => 'left'), array('content' => '<input type="text" name="poll-answers-table-votes-' . $lang . '[' . $uid . ']" value="' . intval($pa['votes']) . '" style="width: 80px;" />', 'align' => 'left'), array('content' => '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" style="cursor: pointer;" onclick="navigate_blocks_poll_answers_table_row_remove(this);" />', 'align' => 'center'))); } } $uid = uniqid(); $table->addRow("poll-answers-table-row-model-" . $lang, array(array('content' => '<input type="text" name="poll-answers-table-title-' . $lang . '[' . $uid . ']" value="" style="width: 200px;" />', 'align' => 'left'), array('content' => '<input type="text" name="poll-answers-table-votes-' . $lang . '[' . $uid . ']" value="0" style="width: 80px;" />', 'align' => 'left'), array('content' => '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" style="cursor: pointer;" onclick="navigate_blocks_poll_answers_table_row_remove(this);" />', 'align' => 'center'))); $navibars->add_tab_content_row(array('<label>' . t(559, "Answers") . '</label>', '<div id="poll-answers-' . $lang . '">' . $table->generate() . '</div>', '<label> </label>', '<button id="poll-answers-table-add-' . $lang . '" data-lang="' . $lang . '"><img src="img/icons/silk/add.png" align="absmiddle" style="cursor:pointer;" /> ' . t(472, 'Add') . '</button>')); $navibars->add_tab_content(' </div> '); } foreach ($website->languages_list as $alang) { $layout->add_script(' $(window).on("load", function() { poll_answers_table_row_models["' . $alang . '"] = $("#poll-answers-table-row-model-' . $alang . '").html(); if($("#poll_answers_table_' . $alang . '").find("tr").not(".nodrag").length > 1) $("#poll-answers-table-row-model-' . $alang . '").hide(); navigate_naviorderedtable_poll_answers_table_' . $alang . '_reorder(); }); '); } $layout->add_script(' var active_languages = ["' . implode('", "', array_keys($options)) . '"]; navigate_items_select_language("' . $website->languages_list[0] . '"); '); break; case 'block': case 'theme': default: $options = array(); foreach ($website->languages_list as $lang) { $options[$lang] = language::name_by_code($lang); } $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $options, $website->languages_list[0], "navigate_items_select_language(this);"))); foreach ($website->languages_list as $lang) { $navibars->add_tab_content('<div class="language_fields" id="language_fields_' . $lang . '" style=" display: none; ">'); $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title-' . $lang, @$item->dictionary[$lang]['title']), '')); $block_trigger_types = array('' => t(181, 'Hidden'), 'title' => t(67, 'Title'), 'content' => t(9, 'Content'), 'image' => t(157, 'Image'), 'rollover' => t(182, 'Rollover'), 'video' => t(272, 'Video'), 'html' => 'HTML', 'links' => t(549, 'Links'), 'flash' => 'Flash'); // check block trigger restrictions in theme definition if (is_array($theme->blocks)) { foreach ($theme->blocks as $tb) { if ($tb->code == $item->type && isset($tb->trigger)) { if (!is_array($tb->trigger)) { $tb->trigger = array($tb->trigger); } foreach ($block_trigger_types as $btt_key => $btt_val) { if (empty($btt_key) || in_array($btt_key, $tb->trigger)) { continue; } unset($block_trigger_types[$btt_key]); } $block_trigger_types = array_filter($block_trigger_types); } } } $navibars->add_tab_content_row(array('<label>' . t(160, 'Type') . '</label>', $naviforms->selectfield('trigger-type-' . $lang, array_keys($block_trigger_types), array_values($block_trigger_types), $item->trigger['trigger-type'][$lang], "navigate_blocks_trigger_change('" . $lang . "', this);"))); $navibars->add_tab_content_row(array('<label>' . t(157, 'Image') . '</label>', $naviforms->dropbox('trigger-image-' . $lang, @$item->trigger['trigger-image'][$lang], 'image'))); $navibars->add_tab_content_row(array('<label>' . t(182, 'Rollover') . ' (off / on)</label>', $naviforms->dropbox('trigger-rollover-' . $lang, @$item->trigger['trigger-rollover'][$lang], 'image'), $naviforms->dropbox('trigger-rollover-active-' . $lang, @$item->trigger['trigger-rollover-active'][$lang], 'image'), '')); $navibars->add_tab_content_row(array('<label>' . t(272, 'Video') . '</label>', $naviforms->dropbox('trigger-video-' . $lang, @$item->trigger['trigger-video'][$lang], 'video'))); $navibars->add_tab_content_row(array('<label>Flash (SWF)</label>', $naviforms->dropbox('trigger-flash-' . $lang, @$item->trigger['trigger-flash'][$lang], 'flash'), '')); /* links list */ // check if navigate must show an icon selector $links_icons = ''; if (!empty($theme) && !empty($theme->blocks)) { foreach ($theme->blocks as $tb) { if ($item->type == $tb->id) { $links_icons = @$tb->icons; break; } } } $table = new naviorderedtable("trigger_links_table_" . $lang); $table->setWidth("776px"); $table->setHiddenInput("trigger-links-table-order-" . $lang); $navibars->add_tab_content($naviforms->hidden("trigger-links-table-order-" . $lang, "")); $table->addHeaderColumn(t(242, 'Icon'), 50); $table->addHeaderColumn(t(67, 'Title'), 200); $table->addHeaderColumn(t(197, 'Link'), 390); $table->addHeaderColumn('<i class="fa fa-external-link" title="' . t(324, 'New window') . '"></i>', 16); $table->addHeaderColumn(t(35, 'Remove'), 50); if (empty($item->trigger['trigger-links'][$lang]['link'])) { // create a default entry $item->trigger['trigger-links'][$lang] = array('order' => '', 'icon' => '', 'title' => array('0' => ''), 'link' => array('0' => '')); } if (!empty($item->trigger['trigger-links'][$lang])) { $tlinks = $item->trigger['trigger-links'][$lang]; foreach ($tlinks['link'] as $key => $link) { $uid = uniqid(); $table->addRow(uniqid('trigger-links-table-row-'), array(empty($links_icons) ? array('content' => '-', 'align' => 'center') : array('content' => '<select name="trigger-links-table-icon-' . $lang . '[' . $uid . ']" data-select2-value="' . $tlinks['icon'][$key] . '" data-role="icon" style="width: 190px;"></select>', 'align' => 'left'), array('content' => '<input type="text" name="trigger-links-table-title-' . $lang . '[' . $uid . ']" value="' . $tlinks['title'][$key] . '" data-role="title" style="width: 250px;" />', 'align' => 'left'), array('content' => '<input type="text" name="trigger-links-table-link-' . $lang . '[' . $uid . ']" value="' . $tlinks['link'][$key] . '" data-role="link" style="width: 260px;" />' . '<a class="uibutton nv_block_nv_link_trigger"><i class="fa fa-sitemap"></i></a>', 'align' => 'left', 'style' => 'white-space: nowrap;'), array('content' => '<input type="checkbox" name="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" data-role="target" id="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" value="1" ' . ($tlinks['new_window'][$key] == '1' ? 'checked="checked"' : '') . ' /> <label for="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" />', 'align' => 'left'), array('content' => '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" style="cursor: pointer;" onclick="navigate_blocks_trigger_links_table_row_remove(this);" />', 'align' => 'center'))); } } $uid = uniqid(); $table->addRow("trigger-links-table-row-model-" . $lang, array(empty($links_icons) ? array('content' => '-', 'align' => 'center') : array('content' => '<select name="trigger-links-table-icon-' . $lang . '[' . $uid . ']" data-select2-value="" data-role="icon" style="width: 190px;"></select>', 'align' => 'left'), array('content' => '<input type="text" name="trigger-links-table-title-' . $lang . '[' . $uid . ']" value="" data-role="title" style="width: 250px;" />', 'align' => 'left'), array('content' => '<input type="text" name="trigger-links-table-link-' . $lang . '[' . $uid . ']" value="" data-role="link" style="width: 260px;" />' . '<a class="uibutton nv_block_nv_link_trigger"><i class="fa fa-sitemap"></i></a>', 'align' => 'left'), array('content' => '<input type="checkbox" name="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" data-role="target" id="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" value="1" /> <label for="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" />', 'align' => 'left'), array('content' => '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" style="cursor: pointer;" onclick="navigate_blocks_trigger_links_table_row_remove(this);" />', 'align' => 'center'))); $navibars->add_tab_content_row(array('<label>' . t(549, "Links") . '</label>', '<div id="trigger-links-' . $lang . '">' . $table->generate() . '</div>', '<label> </label>', '<button id="trigger-links-table-add-' . $lang . '" data-lang="' . $lang . '"><img src="img/icons/silk/add.png" align="absmiddle" style="cursor:pointer;" /> ' . t(472, 'Add') . '</button>')); $navibars->add_tab_content_row(array('<label>HTML</label>', $naviforms->scriptarea('trigger-html-' . $lang, @$item->trigger['trigger-html'][$lang]), '')); $editor_width = ""; if (!empty($block_type_width)) { if ($block_type_width > 500) { $editor_width = $block_type_width . 'px'; } else { $editor_width = '500px'; } } $translate_menu = ''; if (!empty($translate_extensions)) { $translate_extensions_titles = array(); $translate_extensions_actions = array(); foreach ($translate_extensions as $te) { if ($te['enabled'] == '0') { continue; } $translate_extensions_titles[] = $te['title']; $translate_extensions_actions[] = 'javascript: navigate_tinymce_translate_' . $te['code'] . '(\'trigger-content-' . $lang . '-' . $lang . '\', \'' . $lang . '\');'; } if (!empty($translate_extensions_actions)) { $translate_menu = $naviforms->splitbutton('translate_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(188, 'Translate'), $translate_extensions_actions, $translate_extensions_titles); } } $navibars->add_tab_content_row(array('<label>' . t(9, "Content") . ' <span class="editor_selector" for="trigger-content-' . $lang . '">' . '<i class="fa fa-border fa-fw fa-lg fa-file-text-o active" data-action="tinymce" title="' . t(614, "Edit with TinyMCE") . '"></i> ' . '<i class="fa fa-border fa-fw fa-lg fa-code" data-action="html" title="' . t(615, "Edit as source code") . '"></i> ' . '<i class="fa fa-border fa-fw fa-lg fa-eraser" data-action="clear" title="' . t(208, "Remove all content") . '"></i>' . '</span>' . '</label>', $naviforms->editorfield('trigger-content-' . $lang, @$item->trigger['trigger-content'][$lang], $editor_width, $lang), '<div style="clear:both; margin-top:5px; float:left; margin-bottom: 10px;">', '<label> </label>', $translate_menu, !empty($theme->content_samples) ? '<button onclick="navigate_blocks_copy_from_theme_samples(\'trigger-content-' . $lang . '\', \'trigger\', \'' . $lang . '\', \'' . "tinymce" . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>', '<br />'), '', 'lang="' . $lang . '"'); $navibars->add_tab_content_row(array('<label>' . t(172, 'Action') . '</label>', $naviforms->selectfield('action-type-' . $lang, array(0 => '', 1 => 'web', 2 => 'web-n', 3 => 'javascript', 4 => 'file', 5 => 'image'), array(0 => t(183, 'Do nothing'), 1 => t(173, 'Open URL'), 2 => t(174, 'Open URL (new window)'), 3 => 'Javascript', 4 => t(175, 'Download file'), 5 => t(176, 'View image')), $item->action['action-type'][$lang], "navigate_blocks_action_change('" . $lang . "', this);"))); /* show/hide appropiate row type by action */ $selected_link_title = ''; if (!empty($item->action['action-web'][$lang])) { $path = explode('/', $item->action['action-web'][$lang]); if (count($path) > 0 && $path[0] == 'nv:') { if ($path[2] == 'structure') { $tmp = new structure(); $tmp->load($path[3]); $selected_link_title = $tmp->dictionary[$lang]['title']; $layout->add_script(' $(".nv_block_nv_link_info[data-lang=' . $lang . ']").find("img[data-type=structure]").removeClass("hidden"); '); } else { if ($path[2] == 'element') { $tmp = new item(); $tmp->load($path[3]); $selected_link_title = $tmp->dictionary[$lang]['title']; $layout->add_script(' $(".nv_block_nv_link_info[data-lang=' . $lang . ']").find("img[data-type=element]").removeClass("hidden"); '); } } } } $navibars->add_tab_content_row(array('<label>' . t(184, 'Webpage') . '</label>', $naviforms->autocomplete('action-web-' . $lang, @$item->action['action-web'][$lang], '?fid=' . $_REQUEST['fid'] . '&act=path'), '<a class="uibutton nv_block_nv_link_trigger"><i class="fa fa-sitemap"></i></a>', '<div class="subcomment nv_block_nv_link_info" data-lang="' . $lang . '"> <img src="img/icons/silk/sitemap_color.png" class="hidden" data-type="structure" sprite="false" /> <img src="img/icons/silk/page.png" class="hidden" data-type="element" sprite="false" /> ' . '<span>' . $selected_link_title . '</span>' . '</div>')); $layout->add_script(' $("input[name=action-web-' . $lang . ']").on("keydown", function() { var div_info = $(this).parent().find(".nv_block_nv_link_info"); $(div_info).find("span").text(""); $(div_info).find("img").addClass("hidden"); }); '); $navibars->add_tab_content_row(array('<label>Javascript</label>', $naviforms->textfield('action-javascript-' . $lang, @$item->action['action-javascript'][$lang], NULL, "navigate_blocks_action_javascript_clean_quotes('action-javascript-" . $lang . "');"), '<div class="subcomment"><img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(606, 'Double quotes not allowed, use single quotes only') . '</div>')); $layout->add_script(' function navigate_blocks_action_javascript_clean_quotes(id) { var content = $("#" + id).val(); content = content.replace(\'"\', "\'"); $("#" + id).val(content); } '); $navibars->add_tab_content_row(array('<label>' . t(82, 'File') . '</label>', $naviforms->dropbox('action-file-' . $lang, @$item->action['action-file'][$lang]), '')); $navibars->add_tab_content_row(array('<label>' . t(157, 'Image') . '</label>', $naviforms->dropbox('action-image-' . $lang, @$item->action['action-image'][$lang], 'image'), '')); // copy from other language if (count($website->languages) > 1) { $block_copyfrom_titles = array(); $block_copyfrom_actions = array(); foreach ($website->languages as $bcpl) { if ($bcpl['language'] == $lang) { continue; } $block_copyfrom_titles[] = language::name_by_code($bcpl['language']); $block_copyfrom_actions[] = 'javascript: navigate_blocks_copy_from_language(\'' . $bcpl['language'] . '\', \'' . $lang . '\');'; } $copy_from_menu = $naviforms->splitbutton('block_copyfrom_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(189, 'Copy from') . '...', $block_copyfrom_actions, $block_copyfrom_titles); $navibars->add_tab_content_row('<label> </label>' . $copy_from_menu); } $navibars->add_tab_content('</div>'); } $layout->add_script(' function navigate_blocks_copy_from_language(from, to) { // copy title (if destination is empty) if($("#title-" + to).val()=="") $("#title-" + to).val($("#title-" + from).val()); // copy trigger type $("#trigger-type-" + to) .val($("#trigger-type-" + from).val()) .trigger("change"); // copy trigger value, depending on the trigger type switch($("#trigger-type-" + to).val()) { case "image": navigate_dropbox_clone_value("trigger-image-" + from, "trigger-image-" + to); break; case "rollover": navigate_dropbox_clone_value("trigger-rollover-" + from, "trigger-rollover-" + to); navigate_dropbox_clone_value("trigger-rollover-active-" + from, "trigger-rollover-active-" + to); break; case "video": navigate_dropbox_clone_value("trigger-video-" + from, "trigger-video-" + to); break; case "flash": navigate_dropbox_clone_value("trigger-flash-" + from, "trigger-flash-" + to); break; case "html": // ncid: navigate codemirror instance destination // ncio: navigate codemirror instance destination for(ncid in navigate_codemirror_instances) { if($(navigate_codemirror_instances[ncid].getTextArea()).attr("id") == "trigger-html-" + to) { for(ncio in navigate_codemirror_instances) { if($(navigate_codemirror_instances[ncio].getTextArea()).attr("id") == "trigger-html-" + from) { navigate_codemirror_instances[ncid].setValue(navigate_codemirror_instances[ncio].getValue()); } } } } $(navigate_codemirror_instances).each(function() { this.refresh(); } ); break; case "links": // remove previous links (if any) $("#trigger-links-" + to).find("tr").not("#trigger-links-table-row-model-" + to).not(":first").remove(); // copy each link in the origin language $("#trigger-links-" + from).find("tr").not("#trigger-links-table-row-model-" + from).not(":first").each(function() { // add a row $("#trigger-links-table-add-" + to).trigger("click"); $(this).find("td").each(function(i) { if($(this).find(".select2-container").length > 0) { // select2 field var input_name = $("#trigger_links_table_" + to).find("tr:visible:last").find("td").eq(i).find("select").attr("name"); var input_value = $(this).find("select").val(); if(input_name) $("select[name=\\""+input_name+"\\"]").val(input_value).trigger("change"); } else { // standard input or checkbox field $("#trigger_links_table_" + to).find("tr:visible:last").find("td").eq(i).find("input").val($(this).find("input").val()); if($(this).find("input").attr("checked")) $("#trigger_links_table_" + to).find("tr:visible:last").find("td").eq(i).find("input").attr("checked", "checked"); } }); }); break; case "content": tinyMCE.get("trigger-content-" + to).setContent( tinyMCE.get("trigger-content-" + from).getContent() ); break; case "title": case "": default: // nothing to do break; } // copy action type $("#action-type-" + to) .val($("#action-type-" + from).val()) .trigger("change"); // copy action value switch($("#action-type-" + to).val()) { case "web": case "web-n": $("#action-web-" + to).val($("#action-web-" + from).val()); break; case "javascript": $("#action-javascript-" + to).val($("#action-javascript-" + from).val()); break; case "file": navigate_dropbox_clone_value("action-file-" + from, "action-file-" + to); break; case "image": navigate_dropbox_clone_value("action-image-" + from, "action-image-" + to); break; case "": default: // nothing to do break; } } '); // right now, only fontawesome icon set is supported $fontawesome_classes = ''; if ($links_icons == 'fontawesome') { $fontawesome_classes = block::fontawesome_list(); $fontawesome_classes = array_map(function ($v) { $x = new stdClass(); $x->id = $v; if (!empty($v)) { $x->text = substr($v, 3); } return $x; }, $fontawesome_classes); } $layout->add_script(' var active_languages = ["' . implode('", "', array_keys($options)) . '"]; navigate_items_select_language("' . $website->languages_list[0] . '"); navigate_fontawesome_classes = ' . json_encode($fontawesome_classes) . '; '); foreach ($website->languages_list as $alang) { $layout->add_script(' $(window).on("load", function() { $("#trigger-type-' . $alang . '").val("' . $item->trigger['trigger-type'][$alang] . '"); $("#action-type-' . $alang . '").val("' . $item->action['action-type'][$alang] . '"); navigate_blocks_trigger_change("' . $alang . '", $("<input type=\\"hidden\\" value=\\"' . $item->trigger['trigger-type'][$alang] . '\\" />")); links_table_row_models["' . $alang . '"] = $("#trigger-links-table-row-model-' . $alang . '").html(); if($("#trigger_links_table_' . $alang . '").find("tr").not(".nodrag").length > 1) $("#trigger-links-table-row-model-' . $alang . '").hide(); // prepare select2 to select icons if(' . ($links_icons == 'fontawesome' ? 'true' : 'false') . ') { $("[id^=trigger_links_table_").find("tr").each(function(i, tr) { // do not apply select2 to head row if(!$(tr).find("select")) return; // do not apply select2 to model row if($(tr).attr("id") && ($(this).attr("id")).indexOf("table-row-model") > 0) return; navigate_blocks_trigger_links_table_icon_selector(tr); }); } }); '); } $layout->add_content(' <div id="navigate_blocks_copy_from_theme_samples" style=" display: none; "> <div class="navigate-form-row"> <label>' . t(79, 'Template') . '</label> <select id="navigate_blocks_copy_from_theme_samples_options" name="navigate_blocks_copy_from_theme_samples_options" onchange="navigate_blocks_copy_from_theme_samples_preview(this.value, $(this).attr(\'type\'), $(this).find(\'option:selected\').attr(\'source\'));"> </select> </div> <div class="navigate-form-row"> <div id="navigate_blocks_copy_from_theme_samples_text" name="navigate_blocks_copy_from_theme_samples_text" style="border: 1px solid #CCCCCC; float: left; height: auto; min-height: 20px; overflow: auto; width: 97%; padding: 3px; background: #f7f7f7;"> </div> <div id="navigate_blocks_copy_from_theme_samples_text_raw" style=" display: none; "></div> </div> </div> '); $layout->add_script(' var theme_content_samples = ' . json_encode($theme->content_samples) . '; var website_theme = "' . $website->theme . '"; '); break; } if (!empty($item->type)) { // we need to know if the block is defined in the active theme or in the database (numeric ID) foreach ($block_types as $bt) { if ($bt['code'] == $item->type) { $block_type_id = $bt['id']; break; } } $properties_html = navigate_property_layout_form('block', $block_type_id, 'block', $item->id); if (!empty($properties_html)) { $navibars->add_tab(t(77, "Properties")); $navibars->add_tab_content($properties_html); } } $navibars->add_tab(t(336, "Display")); $default_value = 1; if (!empty($item->categories)) { $default_value = 0; } else { if (!empty($item->exclusions)) { $default_value = 2; } } $navibars->add_tab_content_row(array('<label>' . t(330, 'Categories') . '</label>', $naviforms->buttonset('all_categories', array('1' => t(396, 'All categories'), '0' => t(405, 'Selection'), '2' => t(552, 'Exclusions')), $default_value))); $hierarchy = structure::hierarchy(0); $categories_list = structure::hierarchyList($hierarchy, $item->categories); $exclusions_list = structure::hierarchyList($hierarchy, $item->exclusions); $navibars->add_tab_content_row(array('<label> </label>', '<div class="category_tree" id="category-tree-parent"> <img src="img/icons/silk/world.png" align="absmiddle" /> ' . $website->name . '<div class="tree_ul">' . $categories_list . '</div>' . '</div>')); $navibars->add_tab_content_row(array('<label> </label>', '<div class="category_tree" id="exclusions-tree-parent"> <img src="img/icons/silk/world.png" align="absmiddle" /> ' . $website->name . '<div class="tree_ul">' . $exclusions_list . '</div>' . '</div>')); if (!is_array($item->categories)) { $item->categories = array(); } if (!is_array($item->exclusions)) { $item->exclusions = array(); } $navibars->add_tab_content($naviforms->hidden('categories', implode(',', $item->categories))); $navibars->add_tab_content($naviforms->hidden('exclusions', implode(',', $item->exclusions))); $elements_display = "all"; if (!empty($item->elements['exclusions'])) { $elements_display = "exclusions"; } else { if (!empty($item->elements['selection'])) { $elements_display = "selection"; } } $navibars->add_tab_content_row(array('<label>' . t(22, 'Elements') . ' ' . t(428, '(no category)') . '</label>', $naviforms->buttonset('elements_display', array('all' => t(443, 'All'), 'selection' => t(405, 'Selection'), 'exclusions' => t(552, 'Exclusions')), $elements_display, "navigate_blocks_elements_display_change(this)"))); $layout->add_script(' function navigate_blocks_elements_display_change(el) { el = $(el).prev(); if($(el).val()=="all") $("#elements_selection_wrapper").hide(); else $("#elements_selection_wrapper").show(); } navigate_blocks_elements_display_change($("label[for=elements_display_' . $elements_display . ']")); '); if (!is_array($item->elements)) { $item->elements = array(); } $items_ids = array_values($item->elements); $items_ids = $items_ids[0]; if (empty($items_ids)) { $items_ids = array(); } $items_titles = array(); for ($i = 0; $i < count($items_ids); $i++) { $item_title = $DB->query_single('text', 'nv_webdictionary', ' node_type = "item" AND website = "' . $website->id . '" AND node_id = "' . $items_ids[$i] . '" AND subtype = "title" AND lang = "' . $website->languages_published[0] . '"'); $items_titles[$i] = $item_title; } $navibars->add_tab_content_row(array('<label> </label>', $naviforms->selectfield("elements_selection", $items_ids, $items_titles, $items_ids, null, true, null, null, false)), "elements_selection_wrapper"); $layout->add_script(' $("#elements_selection").select2({ placeholder: "' . t(533, "Find element by title") . '", minimumInputLength: 1, ajax: { url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=items&act=json_find_item", dataType: "json", delay: 100, data: function(params) { return { title: params.term, //association: "free", embedding: 0, nd: new Date().getTime(), page_limit: 30, // page size page: params.page // page number }; }, processResults: function (data, params) { params.page = params.page || 1; return { results: data.items, pagination: { more: (params.page * 30) < data.total_count } }; } }, templateSelection: function(row) { if(row.id) return row.text + " <helper style=\'opacity: .5;\'>#" + row.id + "</helper>"; else return row.text; }, escapeMarkup: function (markup) { return markup; }, // let our custom formatter work triggerChange: true }); $("#elements_selection_wrapper").find(".select2-search__field").css("width", "408px"); $("#elements_selection_wrapper").find("li.select2-search").css("width", "auto"); '); if (!empty($item->type)) { $navibars->add_tab(t(171, 'Order')); // order blocs of the same type $DB->query('SELECT b.id as id, d.text as title, b.fixed as fixed FROM nv_blocks b, nv_webdictionary d WHERE b.type = "' . $item->type . '" AND d.node_type = "block" AND d.subtype = "title" AND d.lang = "' . $website->languages_list[0] . '" AND d.node_id = b.id AND d.website = ' . $website->id . ' AND b.website = ' . $website->id . ' ORDER BY b.position ASC'); $block_ids = $DB->result('id'); $blocks = $DB->result(); $navibars->add_tab_content($naviforms->hidden('blocks-order', implode('#', $block_ids))); $table = new naviorderedtable("blocks_order_table"); $table->setWidth("408px"); $table->setHiddenInput("blocks-order"); $table->addHeaderColumn('ID', 50); $table->addHeaderColumn(t(67, 'Title'), 350); $table->addHeaderColumn('<div style=" text-align: center; ">' . t(394, 'Fixed') . '</div>', 50); foreach ($blocks as $block) { $table->addRow($block->id, array(array('content' => $block->id, 'align' => 'left'), array('content' => $block->title, 'align' => 'left'), array('content' => '<span class="checkbox-wrapper"> <input type="checkbox" name="blocks-order-fixed[' . $block->id . ']" id="blocks-order-fixed[' . $block->id . ']" value="1" ' . ($block->fixed == '1' ? 'checked="checked"' : '') . ' /> <label for="blocks-order-fixed[' . $block->id . ']" /> </span>', 'align' => 'center'))); } $navibars->add_tab_content_row(array('<label>' . t(23, 'Blocks') . '</label>', '<div>' . $table->generate() . '</div>', '<div class="subcomment"><img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, 'Drag any row to assign priorities') . '</div>', '<div class="subcomment"><span class="ui-icon ui-icon-lightbulb" style=" float: left; margin-right: 4px; "></span> ' . t(395, '"Fixed" assigns a static position when the order is random') . '</div>')); } return $navibars->generate(); }
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); }
function nvweb_search($vars = array()) { global $website; global $webuser; global $DB; global $current; global $cache; global $structure; global $theme; $out = array(); $search_what = $_REQUEST[$vars['request']]; $search_archive = array(); if (!empty($_REQUEST['archive'])) { $search_archive = explode("-", $_REQUEST['archive']); } // YEAR, MONTH, CATEGORIES (separated by commas) if (isset($_REQUEST[$vars['request']]) || !empty($search_archive[0]) && !empty($search_archive[1])) { // LOG search request $wu_id = 0; if (!empty($webuser->id)) { $wu_id = $webuser->id; } $DB->execute(' INSERT INTO nv_search_log (id, website, date, webuser, origin, text) VALUES (0, :website, :date, :webuser, :origin, :text) ', array('website' => $website->id, 'date' => time(), 'webuser' => $wu_id, 'origin' => empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'], 'text' => $search_what)); // prepare and execute the search $search_what = explode(' ', $search_what); $search_what = array_filter($search_what); if (empty($search_what)) { $search_what = array(); } $likes = array(); $likes[] = ' 1=1 '; foreach ($search_what as $what) { if (substr($what, 0, 1) == '-') { $likes[] = 'd.text NOT LIKE ' . protect('%' . substr($what, 1) . '%') . ' AND i.id IN( SELECT p.node_id FROM nv_properties_items p WHERE p.element = "item" AND p.website = ' . protect($website->id) . ' AND p.value NOT LIKE ' . protect('%' . substr($what, 1) . '%') . ' )'; } else { $likes[] = 'd.text LIKE ' . protect('%' . $what . '%') . ' OR i.id IN( SELECT p.node_id FROM nv_properties_items p WHERE p.element = "item" AND p.website = ' . protect($website->id) . ' AND p.value LIKE ' . protect('%' . $what . '%') . ' )'; } } if (!empty($search_archive)) { $start_date = gmmktime(0, 0, 0, $search_archive[1], 1, $search_archive[0]); $end_date = gmmktime(0, 0, 0, $search_archive[1] + 1, 1, $search_archive[0]); $likes[] = ' (i.date_to_display >= ' . $start_date . ')'; $likes[] = ' (i.date_to_display <= ' . $end_date . ')'; } if (!empty($search_archive[2])) { $vars['categories'] = $search_archive[2]; } $categories = NULL; if (isset($vars['categories'])) { if ($vars['categories'] == 'all') { $categories = array(0); $vars['children'] = 'true'; } else { if ($vars['categories'] == 'parent') { $categories = array($current['object']->id); $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'])); } if (empty($categories)) { $categories = $vars['categories']; } 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; } // apply a filter on categories, if given // example: request_categories="c" ... in the url &q=text&c=23,35 if (!empty($vars['request_categories'])) { $categories_filter = explode(",", $_REQUEST[$vars['request_categories']]); if (empty($categories)) { // note: categories may be empty by the rules applies on categories + children; // in this case we give preference to the request_categories filter $categories = array_values($categories_filter); } else { for ($cf = 0; $cf < count($categories_filter); $cf++) { if (!in_array($categories_filter[$cf], $categories)) { unset($categories_filter[$cf]); } $categories_filter = array_filter($categories_filter); } $categories = $categories_filter; } } // retrieve entries $permission = !empty($_SESSION['APP_USER#' . APP_UNIQUE]) ? 1 : 0; $access = !empty($current['webuser']) ? 1 : 2; if (empty($_GET['page'])) { $_GET['page'] = 1; } $offset = intval($_GET['page'] - 1) * $vars['items']; // 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); if (empty($vars['items']) || $vars['items'] == '0') { $vars['items'] = 500; //2147483647; // maximum integer // NOTE: having >500 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 } } // TODO: try to optimize search to use less memory and increase the maximum number of items $DB->query(' SELECT SQL_CALC_FOUND_ROWS rs.id FROM ( SELECT i.id as 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, i.position as position, wd.text as title FROM nv_items i, nv_webdictionary d LEFT JOIN nv_webdictionary wd ON wd.node_id = d.node_id AND wd.lang = ' . protect($current['lang']) . ' AND wd.node_type = "item" AND wd.website = ' . protect($website->id) . ' 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.access = 0 OR i.access = ' . $access . ') AND d.website = ' . protect($website->id) . ' AND d.node_id = i.id AND d.lang = ' . protect($current['lang']) . ' AND (d.node_type = "item" OR d.node_type = "tags") AND ( ' . implode(' AND ', $likes) . ' ) ' . (empty($categories) ? '' : 'AND category IN(' . implode(",", $categories) . ')') . ' ' . $orderby . ' ) rs GROUP BY rs.id LIMIT ' . $vars['items'] . ' OFFSET ' . $offset); $rs = $DB->result(); $total = $DB->foundRows(); for ($i = 0; $i < count($rs); $i++) { if (empty($rs[$i]->id)) { break; } $item = new item(); $item->load($rs[$i]->id); // get the nv list template $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); $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 $template_tags = nvweb_tags_extract($item_html, 'nvlist', true, true, 'UTF-8'); // selfclosing = true if (empty($item_html)) { $item_html = array(); $item_html[] = '<div class="search-result-item">'; $item_html[] = ' <div class="search-result-title"><a href="' . $website->absolute_path() . $item->paths[$current['lang']] . '">' . $item->dictionary[$current['lang']]['title'] . '</a></div>'; $item_html[] = ' <div class="search-result-summary">' . core_string_cut($item->dictionary[$current['lang']]['section-main'], 300, '…') . '</div>'; $item_html[] = '</div>'; $item_html = implode("\n", $item_html); $out[] = $item_html; } else { // parse special template tags foreach ($template_tags as $tag) { $content = nvweb_list_parse_tag($tag, $item, $vars['source'], $i, $i + $offset, $total); $item_html = str_replace($tag['full_tag'], $content, $item_html); } $out[] = $item_html; } } if ($total == 0) { $search_results_empty_text = $theme->t("no_results_found"); if (isset($vars['no_results_found'])) { $search_results_empty_text = $theme->t($vars["no_results_found"]); } if (empty($search_results_empty_text) || $search_results_empty_text == 'no_results_found') { $search_results_empty_text = t(645, "No results found"); } // display the error message only if // 1) it's not empty // 2) the template is preventing the display of any error message in the search ( no_results_found="" ) if (!empty($search_results_empty_text) && (!isset($vars['no_results_found']) || isset($vars['no_results_found']) && !empty($vars['no_results_found']))) { $out[] = '<div class="search-results-empty">'; $out[] = $search_results_empty_text; $out[] = '</div>'; } } $archive = $_REQUEST['archive']; if (!empty($archive)) { $archive = 'archive=' . $archive . '&'; } if (isset($vars['paginator']) && $vars['paginator'] != 'false') { $search_url = '?' . $archive . $vars['request'] . '=' . $_REQUEST[$vars['request']] . '&page='; $out[] = nvweb_list_paginator($vars['paginator'], $_GET['page'], $total, $vars['items'], $vars, $search_url); } } return implode("\n", $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; }
// include some utils functions include_once get_module_path('CLLP') . '/lib/utils.lib.php'; require_once get_module_path('CLLP') . '/lib/item.class.php'; if ($totalGrade > 0) { $scoreRaw = $totalResult / $totalGrade * 100; $scoreMin = 0; $scoreMax = 100; } else { $scoreRaw = $scoreMin = $scoreMax = 0; $completionStatus = 'incomplete'; } $completionStatus = 'incomplete'; if (isset($_SESSION['thisItemId'])) { $itemId = (int) $_SESSION['thisItemId']; $item = new item(); if ($item->load($itemId)) { if ($scoreRaw >= (int) $item->getCompletionThreshold()) { $completionStatus = 'completed'; } } } $sessionTime = unixToScormTime($timeToCompleteExe); $jsForLP = '' . 'doSetValue("cmi.score.raw","' . $scoreRaw . '");' . "\n" . 'doSetValue("cmi.score.min","' . $scoreMin . '");' . "\n" . 'doSetValue("cmi.score.max","' . $scoreMax . '");' . "\n" . 'doSetValue("cmi.session_time","' . $sessionTime . '");' . "\n" . 'doSetValue("cmi.completion_status","' . $completionStatus . '");' . "\n" . 'doTerminate();' . "\n"; } // old learning path tool if (isset($_SESSION['inPathMode']) && $_SESSION['inPathMode']) { set_learning_path_progression($totalResult, $totalGrade, $timeToCompleteExe, claro_get_current_user_id()); } } } elseif (!$exerciseIsAvailable) { $showResult = false;
function nvweb_comments_list($offset = 0, $limit = NULL, $permission = NULL, $order = 'oldest') { global $DB; global $website; global $current; $limit = value_or_default($limit, 2147483647); if ($order == 'newest' || $order == 'hierarchy_newest') { $orderby = "nvc.date_created DESC"; } else { $orderby = "nvc.date_created ASC"; } $element = $current['object']; if ($current['type'] == 'structure') { if (empty($current['structure_elements'])) { $current['structure_elements'] = $element->elements(); } $element = $current['structure_elements'][0]; } else { if ($current['type'] == 'item') { $element = new item(); $element->load($current['id']); } } if (strpos($order, 'hierarchy') !== false) { // list comments keeping hierarchy // MySQL (still) does not have recursive queries, meanwhile we apply the following procedure: // find all comments of 0-depth (root level) and calculate if they have any reply // then, in PHP, parse the results and load (recursively) all replies and subreplies // in the result array, INSERT the additional results in the position where they must be respecting the order requested (oldest/newest) // note 1: this procedure allows optimization, for now we've made it work // note 2: the only drawback is that offset/limit it's only taken into account for the root level comments, so the // number of results is variable on each request; we found that an acceptable drawback $DB->query(' SELECT SQL_CALC_FOUND_ROWS nvc.*, nvwu.username, nvwu.avatar, (SELECT COUNT(nvcr.id) FROM nv_comments nvcr WHERE nvcr.reply_to = nvc.id AND nvcr.status = 0 ) AS replies FROM nv_comments nvc LEFT OUTER JOIN nv_webusers nvwu ON nvwu.id = nvc.user WHERE nvc.website = ' . protect($website->id) . ' AND nvc.item = ' . protect($element->id) . ' AND nvc.status = 0 AND nvc.reply_to = 0 ORDER BY ' . $orderby . ' LIMIT ' . $limit . ' OFFSET ' . $offset); $rs = $DB->result(); $out = array(); for ($r = 0; $r < count($rs); $r++) { $rows_to_add = array(); if ($rs[$r]->replies > 0) { $c = new comment(); $c->load_from_resultset(array($rs[$r])); $rows_to_add = $c->get_replies(); } $out[] = $rs[$r]; if (!empty($rows_to_add)) { foreach ($rows_to_add as $rta) { $out[] = $rta; } } } $rs = $out; $total = count($rs); } else { $DB->query(' SELECT SQL_CALC_FOUND_ROWS nvc.*, nvwu.username, nvwu.avatar FROM nv_comments nvc LEFT OUTER JOIN nv_webusers nvwu ON nvwu.id = nvc.user WHERE nvc.website = ' . protect($website->id) . ' AND nvc.item = ' . protect($element->id) . ' AND nvc.status = 0 ORDER BY ' . $orderby . ' LIMIT ' . $limit . ' OFFSET ' . $offset); $rs = $DB->result(); $total = $DB->foundRows(); } return array($rs, $total); }
function comments_form($item) { global $DB; global $website; global $layout; global $events; global $theme; $navibars = new navibars(); $naviforms = new naviforms(); if (empty($item->id)) { $navibars->title(t(250, 'Comments') . ' / ' . t(38, 'Create')); } else { $navibars->title(t(250, 'Comments') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']'); } if (empty($item->id)) { $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>')); } else { $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>', '<a href="#" onclick="navigate_delete_dialog();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>')); $delete_html = array(); $delete_html[] = '<div id="navigate-delete-dialog" class="hidden">' . t(57, 'Do you really want to delete this item?') . '</div>'; $delete_html[] = '<script language="javascript" type="text/javascript">'; $delete_html[] = 'function navigate_delete_dialog()'; $delete_html[] = '{'; $delete_html[] = '$("#navigate-delete-dialog").removeClass("hidden");'; $delete_html[] = '$("#navigate-delete-dialog").dialog({ resizable: true, height: 150, width: 300, modal: true, title: "' . t(59, 'Confirmation') . '", buttons: { "' . t(35, 'Delete') . '": function() { $(this).dialog("close"); window.location.href = "?fid=' . $_REQUEST['fid'] . '&act=remove&id=' . $item->id . '"; }, "' . t(58, 'Cancel') . '": function() { $(this).dialog("close"); } } });'; $delete_html[] = '}'; $delete_html[] = '</script>'; $navibars->add_content(implode("\n", $delete_html)); } $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=comments&act=edit"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=comments&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>', 'search_form')); $navibars->form(); $navibars->add_tab(t(43, "Main")); $navibars->add_tab_content($naviforms->hidden('form-sent', 'true')); $navibars->add_tab_content($naviforms->hidden('id', $item->id)); $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . (!empty($item->id) ? $item->id : t(52, '(new)')) . '</span>')); $navibars->add_tab_content($naviforms->hidden('comment-item', $item->item)); if ($item->item > 0) { $content = new item(); $content->load($item->item); $title = $content->dictionary[$website->languages_list[0]]['title']; } $navibars->add_tab_content_row(array('<label>' . t(180, 'Item') . '</label>', $naviforms->textfield('comment-item-text', $title))); $layout->add_script(' $("#comment-item-text").autocomplete( { source: function(request, response) { var toFind = { "title": request.term, "lang": "' . $website->languages[0] . '", nd: new Date().getTime() }; $.ajax( { url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=91", dataType: "json", method: "GET", data: toFind, success: function( data ) { response( data ); } }); }, minLength: 1, select: function(event, ui) { $("#comment-item").val(ui.item.id); } }); '); $webuser_id = ''; if (!empty($item->user)) { $webuser_username = $DB->query_single('username', 'nv_webusers', ' id = ' . $item->user); if (!empty($webuser_username)) { $webuser_username = array($webuser_username); $webuser_id = array($item->user); } } $navibars->add_tab_content_row(array('<label>' . t(1, 'User') . '</label>', $naviforms->selectfield('comment-user', $webuser_id, $webuser_username, $item->user, null, false, null, null, false), '<span style="display: none;" id="comment-user-helper">' . t(535, "Find user by name") . '</span>')); $layout->add_script(' $("#comment-user").select2( { placeholder: $("#comment-user-helper").text(), minimumInputLength: 1, ajax: { url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '" + "&act=json_find_webuser", dataType: "json", delay: 100, data: function (params) { return { username: params.term, nd: new Date().getTime(), page_limit: 30, // page size page: params.page // page number }; }, processResults: function (data, params) { params.page = params.page || 1; return { results: data.items, pagination: { more: (params.page * 30) < data.total_count } }; } }, templateSelection: function(row) { if(row.id) return row.text + " <helper style=\'opacity: .5;\'>#" + row.id + "</helper>"; else return row.text; }, escapeMarkup: function (markup) { return markup; }, triggerChange: true, allowClear: true }); '); $navibars->add_tab_content_row(array('<label>' . t(159, 'Name') . '</label>', $naviforms->textfield('comment-name', $item->name))); $navibars->add_tab_content_row(array('<label>' . t(44, 'E-Mail') . '</label>', $naviforms->textfield('comment-email', $item->email))); $navibars->add_tab_content_row(array('<label>' . t(177, 'Website') . '</label>', $naviforms->textfield('comment-url', $item->url))); $reply_to_comment = ''; if (empty($item->reply_to)) { $item->reply_to = ''; } else { $c = new comment(); $c->load($item->reply_to); $reply_to_comment = $c->author_name() . ' ' . core_ts2date($c->date_created, true); } $navibars->add_tab_content_row(array('<label>' . t(649, 'In reply to') . '</label>', $naviforms->selectfield('comment-reply_to', $item->reply_to, array($reply_to_comment), $item->reply_to, null, false, null, null, false))); $layout->add_script(' $("#comment-reply_to").select2( { placeholder: "", minimumInputLength: 1, ajax: { url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=comments&act=json_find_comment", dataType: "json", delay: 100, data: function (params) { return { search: params.term, node_id: $("#comment-item").val(), maxdate: ' . ($item->date_created + 0) . ', exclude: ' . ($item->id + 0) . ', nd: new Date().getTime(), page_limit: 30, // page size page: params.page // page number }; }, processResults: function (data, params) { params.page = params.page || 1; return { results: data.items, pagination: { more: (params.page * 30) < data.total_count } }; } }, templateSelection: function(row) { if(row.id) return row.text + " <helper style=\'opacity: .5;\'>#" + row.id + "</helper>"; else return row.text; }, escapeMarkup: function (markup) { return markup; }, triggerChange: true, allowClear: true }); '); $navibars->add_tab_content_row(array('<label>' . t(54, 'Text') . '</label>', $naviforms->textarea('comment-message', $item->message, 10))); if (!empty($item->ip)) { $navibars->add_tab_content_row(array('<label>IP</label>', $item->ip)); } if (empty($item->date_created)) { $item->date_created = time(); } $navibars->add_tab_content_row(array('<label>' . t(226, 'Date created') . '</label>', $naviforms->datefield('comment-date_created', $item->date_created, true))); if ($item->date_modified > 0) { $navibars->add_tab_content_row(array('<label>' . t(227, 'Date modified') . '</label>', core_ts2date($item->date_modified, true), empty($item->last_modified_by) ? '' : '(' . user::username_of($item->last_modified_by) . ')')); } $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $naviforms->selectfield('comment-status', array(0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => -1), array(0 => t(64, 'Published'), 1 => t(251, 'Private'), 2 => t(181, 'Hidden'), 3 => t(466, 'Spam'), 4 => t(257, 'To review')), $item->status, '', false, array(0 => t(360, 'Visible to everybody'), 1 => t(359, 'Visible only to Navigate CMS users'), 2 => t(358, 'Hidden to everybody'), 3 => t(358, 'Hidden to everybody'), 4 => t(358, 'Hidden to everybody'))))); if (!empty($item->item)) { $element = new item(); $element->load($item->item); $template = $theme->templates($element->template); if (is_object($template->comments) && isset($template->comments->properties)) { $properties_html = navigate_property_layout_form('comment', $element->template, 'comment', $item->id); if (!empty($properties_html)) { $navibars->add_tab(t(77, "Properties")); $navibars->add_tab_content($properties_html); } } } $events->trigger('comment', 'edit', array('comment' => &$item, 'navibars' => &$navibars, 'naviforms' => &$naviforms)); return $navibars->generate(); }
function nvweb_conditional($vars = array()) { global $website; global $DB; global $current; global $cache; global $structure; global $webgets; global $webuser; $out = array(); $webget = 'conditional'; $categories = array(); $item = new item(); if ($current['type'] == 'item') { $item->load($current['object']->id); $item_type = 'element'; } else { $item_type = 'structure'; if (isset($vars['scope']) && $vars['scope'] == 'element') { // the current path belongs to a structure category, but the template is asking for an element value, // so we try to find the first element assigned to the current category $categories = array(); if (!empty($current['object']->id)) { $categories = array($current['object']->id); } if (isset($vars['categories'])) { $categories = explode(',', $vars['categories']); $categories = array_filter($categories); // remove empty elements } $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; $access_extra_items = str_replace('s.', 'i.', $access_extra); if (empty($categories)) { // force executing the query; search in all categories $categories = nvweb_menu_get_children(array(0)); } // default source for retrieving items $DB->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 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']) . ' ' . $orderby . ' LIMIT 1 OFFSET 0'); $rs = $DB->result(); // now we have the element against which the condition will be checked $i = 0; $item->load($rs[$i]->id); $item_type = 'element'; } else { if (!isset($vars['scope']) || $vars['scope'] == 'structure') { $item = $current['object']; $item_type = 'structure'; } } } // get the template $item_html = $vars['_template']; // now, parse the conditional tags (with html source code inside) switch ($vars['by']) { case 'property': $property_value = NULL; $property_name = $vars['property_name']; if (empty($vars['property_name'])) { $property_name = $vars['property_id']; } if ($vars['property_scope'] == "element") { $property_value = $item->property($property_name); } else { if ($vars['property_scope'] == "structure") { $property = nvweb_properties(array('mode' => 'structure', 'property' => $property_name, 'return' => 'object')); if (!empty($property)) { $property_value = $property->value; } } else { if ($vars['property_scope'] == "website") { $property_value = $website->theme_options->{$property_name}; } else { // no scope defined, so we have to check ELEMENT > STRUCTURE > WEBSITE (the first with a property with the given name) // element $property_value = $item->property($property_name); if (!$item->property_exists($property_name) && $item_type == 'structure') { // get the first embedded element and check find the property $ci = nvweb_content_items(array($item->id), true, 1, true, 'priority'); $item = new item(); if (isset($ci[0])) { $item->load($ci[0]->id); $property_value = $item->property($property_name); } } if (!$item->property_exists($property_name)) { // structure $property = nvweb_properties(array('mode' => 'structure', 'property' => $property_name, 'return' => 'object')); if (!empty($property)) { $property_value = $property->value; } else { // website if (isset($website->theme_options->{$property_name})) { $property_value = $website->theme_options->{$property_name}; } else { $property_value = ''; } } } } } } // if the property is multilanguage, get the value for the current language if (is_array($property_value)) { $property_value = $property_value[$current['lang']]; } // check the given condition if (isset($vars['empty']) || isset($vars['property_empty'])) { if (@$vars['empty'] == 'true' || @$vars['property_empty'] == 'true') { if (empty($property_value)) { $out = $item_html; } else { $out = ''; } } else { if (@$vars['empty'] == 'false' || @$vars['property_empty'] == 'false') { if (!empty($property_value)) { $out = $item_html; } else { $out = ''; } } } } else { if (isset($vars['property_value'])) { $condition_value = $vars['property_value']; switch ($vars['property_compare']) { case '>': case 'gt': $condition = $property_value > $condition_value; break; case '<': case 'lt': $condition = $property_value < $condition_value; break; case '>=': case '=>': case 'gte': $condition = $property_value >= $condition_value; break; case '<=': case '=<': case 'lte': $condition = $property_value <= $condition_value; break; case 'in': $condition_values = explode(",", $condition_value); $condition = in_array($property_value, $condition_values); break; case 'nin': $condition_values = explode(",", $condition_value); $condition = !in_array($property_value, $condition_values); break; case '!=': case 'neq': if (is_numeric($property_value)) { if ($condition_value == 'true' || $condition_value === true) { $condition_value = '1'; } else { if ($condition_value == 'false' || $condition_value === false) { $condition_value = '0'; } } } $condition = $property_value != $condition_value; break; case '=': case '==': case 'eq': default: if (is_numeric($property_value)) { if ($condition_value == 'true' || $condition_value === true) { $condition_value = '1'; } else { if ($condition_value == 'false' || $condition_value === false) { $condition_value = '0'; } } } $condition = $property_value == $condition_value; break; } if ($condition) { $out = $item_html; } else { $out = ''; } } } break; case 'template': case 'templates': $templates = array(); if (isset($vars['templates'])) { $templates = explode(",", $vars['templates']); } else { if (isset($vars['template'])) { $templates = array($vars['template']); } } if (in_array($item->template, $templates)) { $out = $item_html; } else { $out = ''; } break; case 'section': $section_empty = empty($item->dictionary[$current['lang']]['section-' . $vars['section']]); if ($vars['empty'] == 'true' && $section_empty || $vars['empty'] == 'false' && !$section_empty) { $out = $item_html; } else { $out = ''; } break; case 'access': $access = 0; switch ($vars['access']) { case 3: case 'webuser_groups': $access = 3; break; case 2: case 'not_signed_in': $access = 2; break; case 1: case 'signed_in': $access = 1; break; case 0: case 'everyone': default: $access = 0; break; } if ($item->access == $access) { $out = $item_html; } else { $out = ''; } break; case 'webuser': if ($vars['signed_in'] == 'true' && !empty($webuser->id)) { $out = $item_html; } else { if ($vars['signed_in'] == 'false' && empty($webuser->id)) { $out = $item_html; } else { $out = ''; } } break; case 'languages': if (count($website->languages_published) >= $vars['min']) { $out = $item_html; } else { if (count($website->languages_published) <= $vars['max']) { $out = $item_html; } } break; case 'language': if ($current['lang'] == $vars['lang']) { $out = $item_html; } break; case 'gallery': if ($vars['empty'] == 'true') { if (empty($item->galleries[0])) { $out = $item_html; } } else { if ($vars['empty'] == 'false') { if (!empty($item->galleries[0])) { $out = $item_html; } } else { if (isset($vars['min']) && count($item->galleries[0]) >= intval($vars['min'])) { $out = $item_html; } else { if (isset($vars['max']) && count($item->galleries[0]) <= intval($vars['max'])) { $out = $item_html; } } } } break; case 'tags': if ($vars['empty'] == 'true') { if (empty($item->dictionary[$current['lang']]['tags'])) { $out = $item_html; } } else { if ($vars['empty'] == 'false') { if (!empty($item->dictionary[$current['lang']]['tags'])) { $out = $item_html; } } } break; case 'comments': $DB->query(' SELECT COUNT(*) as total FROM nv_comments WHERE website = ' . protect($website->id) . ' AND item = ' . protect($item->id) . ' AND status = 0 '); $rs = $DB->result(); $comments_count = $rs[0]->total + 0; if (isset($vars['allowed'])) { if ($vars['allowed'] == 'true' || $vars['allowed'] == '1' || empty($vars['allowed'])) { // comments allowed to everybody (2) or to registered users only (1) if ($item->comments_enabled_to == 2 || $item->comments_enabled_to == 1 && !empty($webuser->id)) { $out = $item_html; } } else { if ($vars['allowed'] == 'false') { // comments not allowed for anyone or for webusers but there is no webuser active right now if ($item->comments_enabled_to == 0 || $item->comments_enabled_to == 1 && empty($webuser->id)) { $out = $item_html; } } } } else { if (isset($vars['min']) && $comments_count >= intval($vars['min'])) { $out = $item_html; } else { if (isset($vars['max']) && $comments_count <= intval($vars['max'])) { $out = $item_html; } } } break; default: // unknown nvlist_conditional, discard $out = ''; } // return the new html code after applying the condition return $out; }