Esempio n. 1
0
/**
 * Return an Item if an Intro or a Featured item is available for display in current disp.
 *
 * @return Item
 */
function &get_featured_Item()
{
    global $Blog;
    global $disp, $disp_detail, $MainList, $FeaturedList;
    global $featured_displayed_item_IDs;
    if ($disp != 'posts' || !isset($MainList)) {
        // If we're not currently displaying posts, no need to try & display a featured/intro post on top!
        $Item = NULL;
        return $Item;
    }
    if (!isset($FeaturedList)) {
        // Don't repeat if we've done this already -- Initialize the featured list only first time this function is called in a skin:
        // Get ready to obtain 1 post only:
        $FeaturedList = new ItemList2($Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), 1);
        // Set default filters for the current page:
        $FeaturedList->set_default_filters($MainList->filters);
        if (!$MainList->is_filtered()) {
            // This is not a filtered page, so we are on the home page.
            // The competing intro-* types are: 'main' and 'all':
            // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first!
            $restrict_to_types = '1500,1600';
        } else {
            // We are on a filtered... it means a category page or sth like this...
            // echo $disp_detail;
            switch ($disp_detail) {
                case 'posts-cat':
                case 'posts-subcat':
                    // The competing intro-* types are: 'cat' and 'all':
                    // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first!
                    $restrict_to_types = '1520,1600';
                    break;
                case 'posts-tag':
                    // The competing intro-* types are: 'tag' and 'all':
                    // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first!
                    $restrict_to_types = '1530,1600';
                    break;
                default:
                    // The competing intro-* types are: 'sub' and 'all':
                    // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first!
                    $restrict_to_types = '1570,1600';
            }
        }
        $FeaturedList->set_filters(array('types' => $restrict_to_types), false);
        // pre_dump( $FeaturedList->filters );
        // Run the query:
        $FeaturedList->query();
        if ($FeaturedList->result_num_rows == 0) {
            // No Intro page was found, try to find a featured post instead:
            $FeaturedList->reset();
            $FeaturedList->set_filters(array('featured' => 1), false);
            // Run the query:
            $FeaturedList->query();
        }
    }
    // Get next featured item
    $Item = $FeaturedList->get_item();
    if ($Item) {
        // Memorize that ID so that it can later be filtered out normal display:
        $featured_displayed_item_IDs[] = $Item->ID;
    }
    return $Item;
}
Esempio n. 2
0
/**
 * If an Intro Post is available, return it. If not, see if a Featured Post is available and return it.
 *
 * Note: this will set the global $FeaturedList which may be used to obtain several featured Items.
 *
 * @param string Name of $disp where we should display it
 * @param string Collection IDs:
 *                 NULL: depend on blog setting "Collections to aggregate"
 *                 empty: current blog only
 *                 "*": all blogs
 *                 "1,2,3":blog IDs separated by comma
 *                 "-": current blog only and exclude the aggregated blogs
 * @return Item
 */
function &get_featured_Item($restrict_disp = 'posts', $coll_IDs = NULL)
{
    global $Blog, $cat;
    global $disp, $disp_detail, $MainList, $FeaturedList;
    global $featured_displayed_item_IDs;
    if ($disp != $restrict_disp || !isset($MainList)) {
        // If we're not currently displaying posts, no need to try & display a featured/intro post on top!
        $Item = NULL;
        return $Item;
    }
    if (!isset($FeaturedList)) {
        // Don't repeat if we've done this already -- Initialize the featured list only first time this function is called in a skin:
        // Get ready to obtain 1 post only:
        $FeaturedList = new ItemList2($Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), 1);
        $featured_list_filters = $MainList->filters;
        if (!empty($cat)) {
            // Get a featured post only of the selected category and don't touch the posts of the child categories:
            $featured_list_filters['cat_array'] = array($cat);
        }
        // Set default filters for the current page:
        $FeaturedList->set_default_filters($featured_list_filters);
        // FIRST: Try to find an Intro post:
        if (!$MainList->is_filtered()) {
            // This is not a filtered page, so we are on the home page.
            if ($restrict_disp == 'front') {
                // Special Front page:
                // Use Intro-Front posts
                $restrict_to_types = '1400';
            } else {
                // Default front page displaying posts:
                // The competing intro-* types are: 'main' and 'all':
                // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first!
                $restrict_to_types = '1500,1600';
            }
        } else {
            // We are on a filtered... it means a category page or sth like this...
            // echo $disp_detail;
            switch ($disp_detail) {
                case 'posts-cat':
                case 'posts-subcat':
                    // The competing intro-* types are: 'cat' and 'all':
                    // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first!
                    $restrict_to_types = '1520,1600';
                    break;
                case 'posts-tag':
                    // The competing intro-* types are: 'tag' and 'all':
                    // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first!
                    $restrict_to_types = '1530,1600';
                    break;
                default:
                    // The competing intro-* types are: 'sub' and 'all':
                    // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first!
                    $restrict_to_types = '1570,1600';
            }
        }
        $FeaturedList->set_filters(array('coll_IDs' => $coll_IDs, 'types' => $restrict_to_types), false);
        // pre_dump( $FeaturedList->filters );
        // Run the query:
        $FeaturedList->query();
        // SECOND: If no Intro, try to find an Featured post:
        if ($FeaturedList->result_num_rows == 0 && $restrict_disp != 'front') {
            // No Intro page was found, try to find a featured post instead:
            $FeaturedList->reset();
            $FeaturedList->set_filters(array('coll_IDs' => $coll_IDs, 'featured' => 1), false);
            // Run the query:
            $FeaturedList->query();
        }
    }
    // Get first Item in the result set.
    $Item = $FeaturedList->get_item();
    if ($Item) {
        // Memorize that ID so that it can later be filtered out of normal display:
        $featured_displayed_item_IDs[] = $Item->ID;
    }
    return $Item;
}