/** * Display the widget! * * @param array MUST contain at least the basic display params */ function display($params) { /** * @var ItemList2 */ global $MainList; global $BlogCache, $Blog; global $Item, $Settings; $this->init_display($params); $blog_ID = intval($this->disp_params['blog_ID']); $listBlog = $blog_ID ? $BlogCache->get_by_ID($blog_ID, false) : $Blog; if (empty($listBlog)) { echo $this->disp_params['block_start']; echo $this->disp_params['block_body_start']; echo T_('The requested Blog doesn\'t exist any more!'); echo $this->disp_params['block_body_end']; echo $this->disp_params['block_end']; return; } // Define default template params that can be rewritten by skin $this->disp_params = array_merge(array('item_first_image_before' => '<div class="item_first_image">', 'item_first_image_after' => '</div>', 'item_first_image_placeholder' => '<div class="item_first_image_placeholder"><a href="$item_permaurl$"></a></div>', 'item_title_before' => '<div class="item_title">', 'item_title_after' => '</div>', 'item_title_single_before' => '', 'item_title_single_after' => '', 'item_excerpt_before' => '<div class="item_excerpt">', 'item_excerpt_after' => '</div>', 'item_content_before' => '<div class="item_content">', 'item_content_after' => '</div>', 'item_images_before' => '<div class="item_images">', 'item_images_after' => '</div>'), $this->disp_params); // Create ItemList // Note: we pass a widget specific prefix in order to make sure to never interfere with the mainlist $limit = intval($this->disp_params['limit']); if ($this->disp_params['disp_teaser']) { // We want to show some of the post content, we need to load more info: use ItemList2 $ItemList = new ItemList2($listBlog, $listBlog->get_timestamp_min(), $listBlog->get_timestamp_max(), $limit, 'ItemCache', $this->code . '_'); } else { // no excerpts, use ItemListLight load_class('items/model/_itemlistlight.class.php', 'ItemListLight'); $ItemList = new ItemListLight($listBlog, $listBlog->get_timestamp_min(), $listBlog->get_timestamp_max(), $limit, 'ItemCacheLight', $this->code . '_'); } $cat_array = sanitize_id_list($this->disp_params['cat_IDs'], true); // Filter list: $filters = array('cat_array' => $cat_array, 'orderby' => $this->disp_params['order_by'], 'order' => $this->disp_params['order_dir'], 'unit' => 'posts', 'coll_IDs' => $this->disp_params['blog_ID']); if ($this->disp_params['item_visibility'] == 'public') { // Get only the public items $filters['visibility_array'] = array('published'); } if (isset($this->disp_params['page'])) { $filters['page'] = $this->disp_params['page']; } if ($this->disp_params['item_type'] != '#') { // Not "default", restrict to a specific type (or '' for all) $filters['types'] = $this->disp_params['item_type']; } if ($this->disp_params['follow_mainlist'] == 'tags') { // Restrict to Item tagged with some tag used in the Mainlist: if (!isset($MainList)) { // Nothing to follow, don't display anything return false; } $all_tags = $MainList->get_all_tags(); if (empty($all_tags)) { // Nothing to follow, don't display anything return false; } $filters['tags'] = implode(',', $all_tags); if (!empty($Item)) { // Exclude current Item $filters['post_ID'] = '-' . $Item->ID; } // fp> TODO: in addition to just filtering, offer ordering in a way where the posts with the most matching tags come first } $chapter_mode = false; if ($this->disp_params['item_group_by'] == 'chapter') { // Group by chapter: $chapter_mode = true; # This is the list of categories to restrict the linkblog to (cats will be displayed recursively) # Example: $linkblog_cat = '4,6,7'; $linkblog_cat = ''; # This is the array if categories to restrict the linkblog to (non recursive) # Example: $linkblog_catsel = array( 4, 6, 7 ); $linkblog_catsel = array(); // $cat_array; // Compile cat array stuff: $linkblog_cat_array = array(); $linkblog_cat_modifier = ''; compile_cat_array($linkblog_cat, $linkblog_catsel, $linkblog_cat_array, $linkblog_cat_modifier, $listBlog->ID); $filters['cat_array'] = $linkblog_cat_array; $filters['cat_modifier'] = $linkblog_cat_modifier; } $ItemList->set_filters($filters, false); // we don't want to memorize these params // Run the query: $ItemList->query(); if (!$ItemList->result_num_rows) { // Nothing to display: return; } // Check if the widget displays only single title $this->disp_params['disp_only_title'] = !($this->disp_params['attached_pics'] != 'none' || $this->disp_params['disp_excerpt'] || $this->disp_params['disp_teaser']); // Start to capture display content here in order to solve the issue to don't display empty widget ob_start(); // This variable used to display widget. Will be set to true when content is displayed $content_is_displayed = false; // Get extra classes depending on widget settings: $block_css_class = $this->get_widget_extra_class(); if (empty($block_css_class)) { // No extra class, Display default wrapper: echo $this->disp_params['block_start']; } else { // Append extra classes for widget block: echo preg_replace('/ class="([^"]+)"/', ' class="$1' . $block_css_class . '"', $this->disp_params['block_start']); } $title = sprintf($this->disp_params['title_link'] ? '<a href="' . $listBlog->gen_blogurl() . '" rel="nofollow">%s</a>' : '%s', $this->disp_params['title']); $this->disp_title($title); echo $this->disp_params['block_body_start']; if ($chapter_mode) { // List grouped by chapter/category: $items_map_by_chapter = array(); $chapters_of_loaded_items = array(); $group_by_blogs = false; $prev_chapter_blog_ID = NULL; while ($iterator_Item =& $ItemList->get_item()) { // Display contents of the Item depending on widget params: $Chapter =& $iterator_Item->get_main_Chapter(); if (!isset($items_map_by_chapter[$Chapter->ID])) { $items_map_by_chapter[$Chapter->ID] = array(); $chapters_of_loaded_items[] = $Chapter; } $items_map_by_chapter[$Chapter->ID][] = $iterator_Item; // Group by blogs if there are chapters from multiple blogs if (!$group_by_blogs && $Chapter->blog_ID != $prev_chapter_blog_ID) { // group by blogs is not decided yet $group_by_blogs = $prev_chapter_blog_ID != NULL; $prev_chapter_blog_ID = $Chapter->blog_ID; } } usort($chapters_of_loaded_items, 'Chapter::compare_chapters'); $displayed_blog_ID = NULL; if ($group_by_blogs && isset($this->disp_params['collist_start'])) { // Start list of blogs echo $this->disp_params['collist_start']; } else { // Display list start, all chapters are in the same group ( not grouped by blogs ) echo $this->disp_params['list_start']; } foreach ($chapters_of_loaded_items as $Chapter) { if ($group_by_blogs && $displayed_blog_ID != $Chapter->blog_ID) { $Chapter->get_Blog(); if ($displayed_blog_ID != NULL) { // Display the end of the previous blog's chapter list echo $this->disp_params['list_end']; } echo $this->disp_params['coll_start'] . $Chapter->Blog->get('shortname') . $this->disp_params['coll_end']; // Display start of blog's chapter list echo $this->disp_params['list_start']; $displayed_blog_ID = $Chapter->blog_ID; } $content_is_displayed = $this->disp_chapter($Chapter, $items_map_by_chapter) || $content_is_displayed; } if ($content_is_displayed) { // End of a chapter list - if some content was displayed this is always required echo $this->disp_params['list_end']; } if ($group_by_blogs && isset($this->disp_params['collist_end'])) { // End of blog list echo $this->disp_params['collist_end']; } } else { // Plain list: echo $this->disp_params['list_start']; /** * @var ItemLight (or Item) */ while ($Item =& $ItemList->get_item()) { // Display contents of the Item depending on widget params: $content_is_displayed = $this->disp_contents($Item) || $content_is_displayed; } if (isset($this->disp_params['page'])) { if (empty($this->disp_params['pagination'])) { $this->disp_params['pagination'] = array(); } $ItemList->page_links($this->disp_params['pagination']); } echo $this->disp_params['list_end']; } echo $this->disp_params['block_body_end']; echo $this->disp_params['block_end']; if ($content_is_displayed) { // Some content is displayed, Print out widget ob_end_flush(); } else { // No content, Don't display widget ob_end_clean(); } }
/** * Display the widget! * * @param array MUST contain at least the basic display params */ function display($params) { /** * @var ItemList2 */ global $MainList; global $BlogCache, $Blog; global $Item; $this->init_display($params); if ($this->disp_params['order_by'] == 'RAND' && isset($this->BlockCache)) { // Do NOT cache if display order is random $this->BlockCache->abort_collect(); } $listBlog = $this->disp_params['blog_ID'] ? $BlogCache->get_by_ID($this->disp_params['blog_ID'], false) : $Blog; if (empty($listBlog)) { echo $this->disp_params['block_start']; echo T_('The requested Blog doesn\'t exist any more!'); echo $this->disp_params['block_end']; return; } // Create ItemList // Note: we pass a widget specific prefix in order to make sure to never interfere with the mainlist $limit = $this->disp_params['limit']; if ($this->disp_params['disp_teaser']) { // We want to show some of the post content, we need to load more info: use ItemList2 $ItemList = new ItemList2($listBlog, $listBlog->get_timestamp_min(), $listBlog->get_timestamp_max(), $limit, 'ItemCache', $this->code . '_'); } else { // no excerpts, use ItemListLight load_class('items/model/_itemlistlight.class.php', 'ItemListLight'); $ItemList = new ItemListLight($listBlog, $listBlog->get_timestamp_min(), $listBlog->get_timestamp_max(), $limit, 'ItemCacheLight', $this->code . '_'); } //$cat_array = sanitize_id_list($this->disp_params['cat_IDs'], true); // Filter list: $filters = array('orderby' => $this->disp_params['order_by'], 'order' => $this->disp_params['order_dir'], 'unit' => 'posts'); if (isset($this->disp_params['page'])) { $filters['page'] = $this->disp_params['page']; } if ($this->disp_params['item_type'] != '#') { // Not "default", restrict to a specific type (or '' for all) $filters['types'] = $this->disp_params['item_type']; } if ($this->disp_params['follow_mainlist'] == 'tags') { // Restrict to Item tagged with some tag used in the Mainlist: if (!isset($MainList)) { // Nothing to follow, don't display anything return false; } $all_tags = $MainList->get_all_tags(); if (empty($all_tags)) { // Nothing to follow, don't display anything return false; } $filters['tags'] = implode(',', $all_tags); if (!empty($Item)) { // Exclude current Item $filters['post_ID'] = '-' . $Item->ID; } // fp> TODO: in addition to just filtering, offer ordering in a way where the posts with the most matching tags come first } $chapter_mode = false; if ($this->disp_params['item_group_by'] == 'chapter') { // Group by chapter: $chapter_mode = true; # This is the list of categories to restrict the linkblog to (cats will be displayed recursively) # Example: $linkblog_cat = '4,6,7'; $linkblog_cat = ''; # This is the array if categories to restrict the linkblog to (non recursive) # Example: $linkblog_catsel = array( 4, 6, 7 ); $linkblog_catsel = array(); // $cat_array; // Compile cat array stuff: $linkblog_cat_array = array(); $linkblog_cat_modifier = ''; compile_cat_array($linkblog_cat, $linkblog_catsel, $linkblog_cat_array, $linkblog_cat_modifier, $listBlog->ID); $filters['cat_array'] = $linkblog_cat_array; $filters['cat_modifier'] = $linkblog_cat_modifier; $filters['orderby'] = 'main_cat_ID ' . $filters['orderby']; } $ItemList->set_filters($filters, false); // we don't want to memorize these params // Run the query: $ItemList->query(); if (!$ItemList->result_num_rows) { // Nothing to display: return; } // Start to capture display content here in order to solve the issue to don't display empty widget ob_start(); // This variable used to display widget. Will be set to true when content is displayed $content_is_displayed = false; if (!$this->disp_params['disp_title'] && in_array($this->disp_params['attached_pics'], array('first', 'all'))) { // Don't display bullets when we show only the pictures $block_css_class = 'nobullets'; } if (empty($block_css_class)) { echo $this->disp_params['block_start']; } else { // Additional class for widget block echo preg_replace('/ class="([^"]+)"/', ' class="$1 ' . $block_css_class . '"', $this->disp_params['block_start']); } $title = sprintf($this->disp_params['title_link'] ? '<a href="' . $listBlog->gen_blogurl() . '" rel="nofollow">%s</a>' : '%s', $this->disp_params['title']); $this->disp_title($title); echo $this->disp_params['list_start']; if ($chapter_mode) { // List grouped by chapter/category: /** * @var ItemLight (or Item) */ while ($Item =& $ItemList->get_category_group()) { // Open new cat: $Chapter =& $Item->get_main_Chapter(); echo $this->disp_params['item_start']; echo '<a href="' . $Chapter->get_permanent_url() . '">' . $Chapter->get('name') . '</a>'; echo $this->disp_params['group_start']; while ($Item =& $ItemList->get_item()) { // Display contents of the Item depending on widget params: $content_is_displayed = $this->disp_contents($Item) || $content_is_displayed; } // Close cat echo $this->disp_params['group_end']; echo $this->disp_params['item_end']; } } else { // Plain list: /** * @var ItemLight (or Item) */ while ($Item =& $ItemList->get_item()) { // Display contents of the Item depending on widget params: $content_is_displayed = $this->disp_contents($Item) || $content_is_displayed; } } if (isset($this->disp_params['page'])) { $ItemList->page_links(); } echo $this->disp_params['list_end']; echo $this->disp_params['block_end']; if ($content_is_displayed) { // Some content is displayed, Print out widget ob_end_flush(); } else { // No content, Don't display widget ob_end_clean(); } }