public function render_region($region) { // Fetch regions (how?) and render them (like _page and _node) global $db; $blocks = $db->select('regions r, regioned_blocks rb, blocks b', "r.region_name = " . $db->escapeAndQuote($region) . " AND r.id = rb.region_id AND rb.block_id = b.id"); foreach ($blocks as $block) { $block = block::load($block); if ($block->available($GLOBALS['url_path'])) { $block->render(); } } }
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 nvweb_blocks($vars = array()) { global $website; global $DB; global $current; global $webgets; global $webuser; global $theme; $webget = 'blocks'; nvweb_blocks_init(); $out = ''; $access = array(); $access[] = 0; if (empty($current['webuser'])) { // 1: only signed in users, 2: only NON signed in users, 3: selected web user groups only $access[] = 2; } else { $access[] = 1; $access[] = 3; } // blocks type cache if (empty($webgets[$webget]['block_types'])) { $webgets[$webget]['block_types'] = block::types(); } $block_types = $webgets[$webget]['block_types']; if ($vars['mode'] == 'single') { $order_mode = 'single'; } else { // get the index for the block type requested $bti = array_multidimensional_search($block_types, array('code' => $vars['type'])); // how must we process this block type $order_mode = @$block_types[$bti]['order']; if (empty($order_mode) || $order_mode == 'theme') { $order_mode = @$vars['mode']; } } // how many blocks of this type we have to show $howmany = @intval($block_types[$bti]['maximum']); if (empty($howmany) || $howmany > intval(@$vars['number']) && !empty($vars['number'])) { $howmany = intval(@$vars['number']) + 0; } // which zone of the block we have to return if (empty($vars['zone'])) { $vars['zone'] = 'block'; } $categories = array(); if (!empty($vars['categories'])) { $categories = explode(',', $vars['categories']); $categories = array_filter($categories); } if (isset($current['object']->category)) { $categories[] = $current['object']->category; } else { $categories[] = $current['category']; } $blocks = array(); $categories_query = ''; $exclusions_query = ''; if (is_array($categories) && !empty($categories[0])) { foreach ($categories as $cq) { $categories_query .= " OR INSTR(CONCAT(',', categories, ','), '," . intval($cq) . ",') > 0 "; $exclusions_query .= " AND INSTR(CONCAT(',', exclusions, ','), '," . intval($cq) . ",') = 0 "; } $categories_query = ' AND (categories = "" ' . $categories_query . ') '; } switch ($order_mode) { case 'single': $query_type = ''; if (!empty($vars['type'])) { $query_type = ' AND type = ' . protect($vars['type']); } $DB->query(' SELECT id, type FROM nv_blocks WHERE enabled = 1 ' . $query_type . ' AND website = ' . $website->id . ' AND (date_published = 0 OR date_published < ' . core_time() . ') AND (date_unpublish = 0 OR date_unpublish > ' . core_time() . ') AND access IN(' . implode(',', $access) . ') ' . $categories_query . ' ' . $exclusions_query . ' AND id = ' . protect($vars['id'])); $row = $DB->first(); if (!empty($row)) { $blocks[] = $row->id; $vars['type'] = $row->type; } break; case 'priority': case 'ordered': $DB->query(' SELECT * FROM nv_blocks WHERE type = ' . protect($vars['type']) . ' AND enabled = 1 AND website = ' . $website->id . ' AND (date_published = 0 OR date_published < ' . core_time() . ') AND (date_unpublish = 0 OR date_unpublish > ' . core_time() . ') AND access IN(' . implode(',', $access) . ') ' . $categories_query . ' ' . $exclusions_query . ' ORDER BY position ASC '); $rows = $DB->result(); foreach ($rows as $row) { if (!nvweb_block_enabled($row)) { continue; } $row = (array) $row; $blocks[] = $row['id']; } break; default: case 'random': // "random" gets priority blocks first // retrieve fixed blocks $DB->query(' SELECT * FROM nv_blocks WHERE type = ' . protect($vars['type']) . ' AND enabled = 1 AND website = ' . $website->id . ' AND (date_published = 0 OR date_published < ' . core_time() . ') AND (date_unpublish = 0 OR date_unpublish > ' . core_time() . ') AND access IN(' . implode(',', $access) . ') AND fixed = 1 ' . $categories_query . ' ' . $exclusions_query . ' ORDER BY position ASC '); $fixed_rows = $DB->result(); $fixed_rows_ids = $DB->result('id'); if (empty($fixed_rows_ids)) { $fixed_rows_ids = array(0); } // now retrieve the other blocks in random order $DB->query(' SELECT * FROM nv_blocks WHERE type = ' . protect($vars['type']) . ' AND enabled = 1 AND website = ' . $website->id . ' AND (date_published = 0 OR date_published < ' . core_time() . ') AND (date_unpublish = 0 OR date_unpublish > ' . core_time() . ') AND access IN(' . implode(',', $access) . ') AND id NOT IN(' . implode(",", $fixed_rows_ids) . ') ' . $categories_query . ' ' . $exclusions_query . ' ORDER BY RAND() '); $random_rows = $DB->result(); // mix rows (fixed and random) // fixed position rows foreach ($fixed_rows as $fr) { if (!nvweb_block_enabled($fr)) { continue; } $blocks[$fr->position] = $fr->id; } // random position rows $pos = 0; foreach ($random_rows as $rr) { if (!nvweb_block_enabled($rr)) { continue; } // find next free position $free = false; while (!$free) { $free = empty($blocks[$pos]); if (!$free) { $pos++; } } $blocks[$pos] = $rr->id; } // sort array by key ksort($blocks); break; } // render the blocks found $shown = 0; $position = 1; $block_objects = array(); foreach ($blocks as $id) { if ($howmany > 0 && $shown >= $howmany) { break; } $block = new block(); $block->load($id); $bt = 'block'; for ($bti = 0; $bti < count($block_types); $bti++) { if ($block->type == $block_types[$bti]['code']) { $bt = $block_types[$bti]['type']; break; } } // SKIP all blocks until a certain position if (isset($vars['position']) && $vars['position'] != $position) { $position++; continue; } // RENDER block zone switch ($vars['zone']) { case 'object': $block_objects[] = clone $block; break; case 'title': $out .= '<span class="block-' . $vars['type'] . '-title" zone="title" ng-block-id="' . $block->id . '">' . $block->dictionary[$current['lang']]['title'] . '</span>'; break; case 'content': case 'block': default: if ($bt == 'theme') { $fn = 'nvweb_' . $website->theme . '_blocks_render'; $out .= '<div class="block-' . $vars['type'] . '" ng-block-id="' . $block->id . '">'; $out .= $fn($block, $vars); $out .= '</div>' . "\n"; } else { $out .= '<div class="block-' . $vars['type'] . '" ng-block-id="' . $block->id . '">'; $out .= nvweb_blocks_render($vars['type'], $block->trigger, $block->action, $vars['zone'], $block, $vars); $out .= '</div>' . "\n"; } break; } // the block requested at a CERTAIN POSITION was this, we've finished if (isset($vars['position']) && $vars['position'] == $position) { break; } $shown++; $position++; } if ($vars['zone'] == 'object') { $out = array($block_objects, count($block_objects)); } return $out; }
function block_group_form($item) { global $DB; global $website; global $layout; global $theme; global $current_version; $navibars = new navibars(); $naviforms = new naviforms(); if (empty($item->id)) { $navibars->title(t(23, 'Blocks') . ' / ' . t(506, 'Groups') . ' / ' . t(38, 'Create')); } else { $navibars->title(t(23, 'Blocks') . ' / ' . t(506, 'Groups') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']'); } if (empty($item->id)) { $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(0);"><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(0);"><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>')); $layout->add_script(' function navigate_delete_dialog() { navigate_confirmation_dialog( function() { window.location.href = "?fid=blocks&act=block_group_delete&id=' . $item->id . '"; }, null, null, "' . t(35, 'Delete') . '" ); } '); } $navibars->add_actions(array('<a href="?fid=' . $_REQUEST['fid'] . '&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/brick.png"> ' . t(23, 'Blocks') . '</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>')); if (!empty($item->id)) { $notes = grid_notes::comments('block_group', $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>')); } $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_group_edit"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_groups_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>')); $navibars->form(); if (!empty($item->id)) { $navibars->add_tab(t(23, "Blocks")); $allowed_types = array(); if (!empty($item->code)) { for ($bg = 0; $bg < count($theme->block_groups); $bg++) { if ($theme->block_groups[$bg]->id == $item->code) { if (isset($theme->block_groups[$bg]->allowed_types)) { $allowed_types = $theme->block_groups[$bg]->allowed_types; } break; } } } $blocks_selected = array(); if (!is_array($item->blocks)) { $item->blocks = array(); } $navibars->add_tab_content($naviforms->hidden('blocks_group_selection', json_encode($item->blocks))); $navibars->add_tab_content($naviforms->hidden('blocks-order', "")); $block_types = block::types(); $lang = $website->languages_published[0]; $extensions_blocks = extension::blocks(); for ($p = 0; $p < count($item->blocks); $p++) { unset($block); switch ($item->blocks[$p]['type']) { case "block": $block = new block(); $block->load($item->blocks[$p]['id']); if (empty($block) || empty($block->type)) { continue; } $blocks_selected[] = ' <div class="block_group_block ui-state-default" data-block-id="' . $block->id . '" data-block-type="block" data-block-uid="' . $item->blocks[$p]['uid'] . '"> <div class="actions"> <a href="?fid=blocks&act=edit&id=' . $block->id . '"><img src="' . NAVIGATE_URL . '/img/icons/silk/pencil.png" /></a> <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a> </div> <div class="title">' . $block->dictionary[$lang]['title'] . '</div> <div class="subcomment"><span style="float: right;">ID ' . $block->id . '</span><img src="img/icons/silk/brick.png" /> ' . $theme->t($block->type) . '</div> </div> '; break; case "block_type": for ($bt = 0; $bt < count($block_types); $bt++) { if ($block_types[$bt]['id'] == $item->blocks[$p]['id']) { $block = $block_types[$bt]; break; } } $blocks_selected[] = ' <div class="block_group_block ui-state-default" data-block-id="' . $block['code'] . '" data-block-type="block_type" data-block-uid="' . $item->blocks[$p]['uid'] . '"> <div class="actions"> <a href="#" data-block-group="' . $block['block_group'] . '" data-block-type-code="' . $block['code'] . '" data-block-type-title="(span)" onclick="navigate_blocks_block_type_title(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/text_horizontalrule.png" /><span class="hidden">' . $item->blocks[$p]['title'] . '</span></a> <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a> </div> <div class="title" title="' . $block['description'] . '">' . $block['title'] . '</div> <div class="subcomment"> <span style="float: right;">ID ' . $block['code'] . '</span> <img src="img/icons/silk/brick_link.png" /> ' . $block['count'] . ' ' . ($block['count'] == 1 ? t(437, "Block") : t(23, "Blocks")) . ' </div> </div> '; break; case "block_group_block": if (is_array($theme->block_groups)) { foreach ($theme->block_groups as $key => $bg) { for ($i = 0; $i < count($bg->blocks); $i++) { if ($bg->blocks[$i]->id == $item->blocks[$p]['id']) { $block = array('code' => $bg->blocks[$i]->id, 'type' => $bg->blocks[$i]->id, 'title' => $theme->t($bg->blocks[$i]->title), 'description' => $theme->t($bg->blocks[$i]->description), 'properties' => $bg->blocks[$i]->properties, 'block_group' => $bg->id); break; } } } } $blocks_selected[] = ' <div class="block_group_block ui-state-default" data-block-id="' . $block['code'] . '" data-block-type="block_group_block" data-block-uid="' . $item->blocks[$p]['uid'] . '"> <div class="actions"> ' . (empty($block['properties']) ? '' : '<a href="#" data-block-group="' . $block['block_group'] . '" data-block-group-block="' . $block['code'] . '" data-block-group-action="settings" onclick="navigate_blocks_group_block_settings(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cog.png" /></a>') . ' <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a> </div> <div class="title" title="' . $block['description'] . '">' . $block['title'] . '</div> <div class="subcomment"><span style="float: right;">ID ' . $block['type'] . '</span><img src="img/icons/silk/bricks.png" /> ' . $theme->t($block['type']) . '</div> </div> '; break; case "extension": $block = $item->blocks[$p]; for ($be = 0; $be < count($extensions_blocks); $be++) { if ($block['id'] == $extensions_blocks[$be]->id) { $extension = new extension(); $extension->load($block['extension']); $blocks_selected[] = ' <div class="block_group_block ui-state-default" data-block-id="' . $block['id'] . '" data-block-type="extension" data-block-extension="' . $block['extension'] . '" data-block-uid="' . $item->blocks[$p]['uid'] . '"> <div class="actions"> ' . (empty($extensions_blocks[$be]->properties) ? '' : '<a href="#" data-block-group="' . $item->code . '" data-block-id="' . $block['id'] . '" data-block-extension="' . $block['extension'] . '" data-block-group-action="settings" onclick="navigate_block_group_extension_block_settings(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cog.png" /></a>') . ' <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a> </div> <div class="title">' . $extension->t($extensions_blocks[$be]->title) . '</div> <div class="subcomment"><span style="float: right;">ID ' . $block['id'] . '</span><img src="img/icons/silk/plugin.png" /> ' . $extension->title . '</div> </div> '; break; } } break; } } $blocks_selected = implode("\n", $blocks_selected); $navibars->add_tab_content('<div id="block_group_selected_blocks" style="width: 49%; float: left; margin-right: 2%;"> <div class="ui-accordion ui-widget ui-helper-reset"> <h3 class="ui-accordion-header ui-state-default ui-accordion-icons ui-accordion-header-active ui-state-active ui-corner-top"> <img src="img/icons/silk/bricks.png" style="vertical-align: middle;" /> ' . t(405, 'Selection') . ' </h3> <div class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active">' . $blocks_selected . '</div> </div> <div class="subcomment"> <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, "Drag any row to assign priorities") . ' </div> </div>'); // **** ADD specific BLOCKS **** $sql = ' SELECT b.type, b.id, d.text as title FROM nv_blocks b LEFT JOIN nv_webdictionary d ON b.id = d.node_id AND d.node_type = "block" AND d.subtype = "title" AND d.lang = "' . $website->languages_list[0] . '" AND d.website = ' . $website->id . ' WHERE b.website = ' . $website->id . ' ORDER BY b.id DESC'; $DB->query($sql); $block_elements = $DB->result(); $block_group_blocks = array(); for ($bg = 0; $bg < count($theme->block_groups); $bg++) { if ($theme->block_groups[$bg]->id == $item->code) { $block_group_blocks = $theme->block_groups[$bg]->blocks; } } // blocks available in the accordion $navibars->add_tab_content('<div id="blocks_available_wrapper" style="float: left; width: 49%; "> <div id="blocks_available_accordion"> <h3><i class="fa fa-fw fa-cube"></i> ' . t(437, 'Block') . '</h3> <div> ' . implode("\n", array_map(function ($b) use($allowed_types) { global $theme; $classes = 'block_group_block ui-state-default'; if (!empty($allowed_types) && !in_array($b->type, $allowed_types)) { $classes .= ' ui-state-disabled hidden'; } $html = '<div class="' . $classes . '" data-block-id="' . $b->id . '" data-block-type="block">' . '<div class="actions"> <a href="?fid=blocks&act=edit&id=' . $b->id . '"><img src="' . NAVIGATE_URL . '/img/icons/silk/pencil.png" /></a> <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a> </div>' . '<div class="title">' . $b->title . '</div>' . '<div class="subcomment"><span style="float: right;">ID ' . $b->id . '</span><img src="img/icons/silk/brick.png" /> ' . $theme->t($b->type) . '</div>' . '</div>'; return $html; }, $block_elements)) . ' <div class="navigate-block_group-accordion-info-link hidden"><i class="fa fa-eye-slash"></i> <a href="#">' . t(646, "Show all unselectable blocks") . '</a></div> </div> <h3><i class="fa fa-fw fa-cubes"></i> ' . t(543, 'Block type') . '</h3> <div> ' . implode("\n", array_map(function ($b) use($allowed_types) { $classes = 'block_group_block ui-state-default'; if (!empty($allowed_types) && !in_array($b['id'], $allowed_types)) { $classes .= ' ui-state-disabled'; } $html = '<div class="' . $classes . '" data-block-id="' . $b['id'] . '" data-block-type="block_type">' . '<div class="actions"> <a href="#" data-block-group="' . $b['block_group'] . '" data-block-type-code="' . $b['code'] . '" data-block-type-title="(span)" onclick="navigate_blocks_block_type_title(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/text_horizontalrule.png" /><span class="hidden">' . $b['block_type_title'] . '</span></a> <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a> </div>' . '<div class="title">' . $b['title'] . '</div>' . '<div class="subcomment"> <span style="float: right;">' . $b['count'] . ' ' . ($b['count'] == 1 ? t(437, "Block") : t(23, "Blocks")) . '</span> <img src="img/icons/silk/brick_link.png" /> ID ' . $b['id'] . '</div>' . '</div>'; return $html; }, $block_types)) . ' </div> <h3><i class="fa fa-fw fa-plus-square-o"></i> ' . t(556, 'Block from group') . ' [' . $theme->t($item->code) . ']</h3> <div> ' . implode("\n", array_map(function ($b) use($item) { global $theme; $html = '<div class="block_group_block ui-state-default" data-block-id="' . $b->id . '" data-block-type="block_group_block" title="' . $theme->t(@$b->description) . '">' . '<div class="actions"> ' . (empty($b->properties) ? '' : '<a href="#" data-block-group="' . $item->code . '" data-block-group-block="' . $b->id . '" data-block-group-action="settings" onclick="navigate_blocks_group_block_settings(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cog.png" /></a>') . ' <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a> </div>' . '<div class="title">' . $theme->t($b->title) . '</div>' . '<div class="subcomment"> <span style="float: right;">ID ' . $b->id . '</span> <img src="img/icons/silk/bricks.png" />' . '</div>' . '</div>'; return $html; }, $block_group_blocks)) . ' </div> <h3><i class="fa fa-fw fa-puzzle-piece"></i> ' . t(327, 'Extensions') . '</h3> <div> ' . implode("\n", array_map(function ($b) use($allowed_types, $item) { $classes = 'block_group_block ui-state-default'; $extension = new extension(); $extension->load($b->_extension); $html = '<div class="' . $classes . '" data-block-id="' . $b->id . '" data-block-type="extension" data-block-extension="' . $b->_extension . '">' . '<div class="actions"> ' . (empty($b->properties) ? '' : '<a href="#" data-block-group="' . $item->code . '" data-block-group-block="' . $b->id . '" data-block-group-action="settings" onclick="navigate_block_group_extension_block_settings(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cog.png" /></a>') . ' <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a> </div>' . '<div class="title">' . $extension->t($b->title) . '</div>' . '<div class="subcomment"><span style="float: right;">ID ' . $b->id . '</span><img src="img/icons/silk/plugin.png" /> ' . $extension->title . '</div>' . '</div>'; return $html; }, $extensions_blocks)) . ' </div> </div> <div class="subcomment"> <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(638, "Disabled blocks are not compatible with the current block group type") . ' </div> </div>'); $block_group_block_types_form = ""; foreach ($website->languages_list as $lang) { $block_group_block_types_form .= ' <div data-lang="' . $lang . '" class="navigate-form-row"> <label style="width: 48px; "><span title="' . language::name_by_code($lang) . '" class="navigate-form-row-language-info"><img align="absmiddle" src="img/icons/silk/comment.png">' . $lang . '</span></label> <input type="text" style=" width: 340px;" name="block_type_title_value[' . $lang . ']" value=""> </div> '; } $navibars->add_tab_content(' <div id="navigate-block-groups-block-type-title" class="hidden"> ' . $block_group_block_types_form . ' <div class="subcomment" style="margin-left: 0;"><img src="img/icons/silk/information.png" /> ' . t(641, "It will only be shown if the template supports it") . '</div> </div> '); $layout->add_script(' function navigate_blocks_block_type_title(el) { var title = $(el).find("span").text(); try { title = jQuery.parseJSON(title); } catch(e) { // not json; do nothing } $("#navigate-block-groups-block-type-title").find("input[type=text]").each(function() { if(typeof(title)=="object") $(this).val(title[$(this).parent().data("lang")]); else $(this).val(title); }); $("#navigate-block-groups-block-type-title").removeClass("hidden"); $("#navigate-block-groups-block-type-title").dialog({ title: navigate_t(67, "Title"), modal: true, width: 428, buttons: [ { text: navigate_t(190, "Ok"), icons: { primary: "ui-icon-check" }, click: function() { var new_value = {}; $("#navigate-block-groups-block-type-title") .find(\'input[type="text"]\').each( function() { new_value[$(this).parent().data("lang")] = $(this).val(); } ); $(el).find("span").text(JSON.stringify(new_value)); blocks_selection_update(); $( this ).dialog( "close" ); } }, { text: navigate_t(58, "Cancel"), icons: { primary: "ui-icon-close" }, click: function() { $( this ).dialog( "close" ); } } ] }); } '); } $navibars->add_tab(t(457, "Information")); $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_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title', $item->title))); $blgroups = array(); for ($blg = 0; $blg < count($theme->block_groups); $blg++) { $blgroups[$theme->block_groups[$blg]->id] = ''; if (!empty($theme->block_groups[$blg]->description)) { $blgroups[$theme->block_groups[$blg]->id] = $theme->t($theme->block_groups[$blg]->description); } } if (!in_array($item->code, $blgroups)) { $blgroups[$item->code] = $item->code; } $navibars->add_tab_content_row(array('<label>' . t(237, 'Code') . '</label>', $naviforms->selectfield('code', array_keys($blgroups), array_keys($blgroups), $item->code, NULL, NULL, array_values($blgroups), "", true, true))); // DEPRECATED field, will be removed. Please use the Notes feature if (!empty($item->notes)) { $navibars->add_tab_content_row(array('<label>' . t(168, 'Notes') . '</label>', $naviforms->textarea('notes', $item->notes))); } if (!empty($item->id)) { $layout->navigate_notes_dialog('block_group', $item->id); } $layout->add_script(' $.getScript("lib/packages/blocks/blocks.js?r=' . $current_version->revision . '", function() { block_groups_onload(); }); '); 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); }