Example #1
0
/**
 * Function which return the HTML output for a brick
 * Parameter: Post ID
 * Parameter: Stack ID - The Stack which is calling this brick
 * Parameter: Brick Number - This is brick number X in this Stack
 */
function mp_brick($post_id, $stack_id = NULL, $brick_number = NULL)
{
    global $mp_stacks_active_bricks;
    //Default outputs back to null
    $first_output = NULL;
    $second_output = NULL;
    $content_output = NULL;
    $html_output = NULL;
    //Alignment
    $post_specific_alignment = get_post_meta($post_id, 'brick_alignment', true);
    //First Media Type
    $mp_stacks_first_content_type = get_post_meta($post_id, 'brick_first_content_type', true);
    //Second Media Type
    $mp_stacks_second_content_type = get_post_meta($post_id, 'brick_second_content_type', true);
    //Add this brick id and content types to the global list of active bricks
    $mp_stacks_active_bricks[$post_id] = array($mp_stacks_first_content_type, $mp_stacks_second_content_type);
    //First Output
    $first_output = has_filter('mp_stacks_brick_content_output') ? apply_filters('mp_stacks_brick_content_output', $first_output, $mp_stacks_first_content_type, $post_id) : NULL;
    //Second Output
    $second_output = has_filter('mp_stacks_brick_content_output') ? apply_filters('mp_stacks_brick_content_output', $second_output, $mp_stacks_second_content_type, $post_id) : NULL;
    //Centered - dont use left and right
    if ($post_specific_alignment == "centered") {
        $brick_container_classes = 'mp-brick-centered';
    } else {
        if ($post_specific_alignment == "allleft") {
            $brick_container_classes = 'mp-brick-allleft';
        } else {
            if ($post_specific_alignment == "allright") {
                $brick_container_classes = 'mp-brick-allright';
            } else {
                $brick_container_classes = NULL;
            }
        }
    }
    //If there is a first output
    $first_content_type_display = empty($first_output) ? 'style="display:block;"' : NULL;
    //If there is a second output
    $second_content_type_display = empty($second_output) ? 'style="display:block;"' : NULL;
    //First Content Type HTML output
    $content_output .= '<div id="mp-brick-' . $post_id . '-first-content-type-container" class="mp-brick-content-type-container ' . $brick_container_classes . '">';
    $content_output .= '<div id="mp-brick-' . $post_id . '-first-content-type" class="mp-brick-first-content-type" ' . $first_content_type_display . '>';
    $content_output .= $first_output;
    $content_output .= '</div>';
    $content_output .= '</div>';
    //Second Content Type HTML output
    $content_output .= '<div id="mp-brick-' . $post_id . '-second-content-type-container" class="mp-brick-content-type-container ' . $brick_container_classes . '">';
    $content_output .= '<div id="mp-brick-' . $post_id . '-second-content-type" class="mp-brick-second-content-type" ' . $second_content_type_display . '>';
    $content_output .= $second_output;
    $content_output .= '</div>';
    $content_output .= '</div>';
    //Extra Brick Attributes
    $extra_brick_attributes = apply_filters('mp_stacks_extra_brick_attributes', NULL, $post_id);
    //Extra Brick Background Attributes
    $extra_brick_bg_attributes = apply_filters('mp_stacks_extra_brick_bg_attributes', NULL, $post_id);
    //Extra Brick Outer Attributes
    $extra_brick_outer_attributes = apply_filters('mp_stacks_extra_brick_outer_attributes', NULL, $post_id);
    //Post class for this brick
    $post_class_string = get_post_meta($post_id, 'brick_class_name', true);
    $post_class_string = apply_filters('mp_stacks_brick_class', $post_class_string, $post_id);
    //Get WordPress Classes for this Brick
    $post_class_array = get_post_class('mp-brick', $post_id);
    //Loop through each WordPress class and add it to the class string
    foreach ($post_class_array as $class) {
        $post_class_string .= ' ' . $class;
    }
    //Actual output
    $html_output .= '<div id="mp-brick-' . $post_id . '" class="' . $post_class_string . '" ' . $extra_brick_attributes . '>';
    //HTML Anchor for this brick
    $html_output .= '<a class="brick-anchor" name="' . sanitize_title(get_the_title($post_id)) . '"></a>';
    //Brick Meta Div
    $html_output .= '<div class="mp-brick-meta">';
    //Action hook to run actions in the meta area for a brick
    do_action('mp_stacks_brick_meta_action', $post_id);
    //Hook custom output to the meta div for this brick
    $html_output .= apply_filters('mp_stacks_brick_meta_output', NULL, $post_id);
    //Edit Brick Link
    if (is_user_logged_in() && current_user_can('edit_theme_options')) {
        $html_output .= '<a class="mp-brick-edit-link" href="' . mp_core_add_query_arg(array('mp-stacks-minimal-admin' => 'true', 'mp_stack_id' => $stack_id, 'containing_page_url' => mp_core_get_current_url()), get_edit_post_link($post_id)) . '" >' . __('Edit This Brick', 'mp_stacks') . '</a>';
        //If this brick is being shown as part of a stack
        if (!empty($stack_id)) {
            //Get Menu Order Info for this Brick
            $mp_stack_order = get_post_meta($post_id, 'mp_stack_order_' . $stack_id, true);
            $mp_stack_order = !empty($mp_stack_order) ? $mp_stack_order : 1000;
            //Tell the user which stack and brick they are editing
            $stack_info = get_term($stack_id, 'mp_stacks');
            $html_output .= '<div class="mp-brick-title-container"><div class="mp-brick-title">' . __('This is Brick ', 'mp_stacks') . $brick_number . ' in the Stack called "' . $stack_info->name . '".</div></div>';
            //Show buttons to add new bricks above/below
            $html_output .= '<a class="mp-brick-add-before-link" href="' . mp_core_add_query_arg(array('post_type' => 'mp_brick', 'mp-stacks-minimal-admin' => 'true', 'mp_stack_id' => $stack_id, 'mp_stack_order_new' => $mp_stack_order - 1, 'containing_page_url' => mp_core_get_current_url()), admin_url('post-new.php')) . '" >' . __('+ Add Brick Before', 'mp_stacks') . '</a>';
            $html_output .= '<a class="mp-brick-add-after-link" href="' . mp_core_add_query_arg(array('post_type' => 'mp_brick', 'mp-stacks-minimal-admin' => 'true', 'mp_stack_id' => $stack_id, 'mp_stack_order_new' => $mp_stack_order + 1, 'containing_page_url' => mp_core_get_current_url()), admin_url('post-new.php')) . '" >' . __('+ Add Brick After', 'mp_stacks') . '</a>';
            //Get number of bricks in this stack
            $number_of_bricks = mp_core_number_postpercat($stack_id);
            //If this brick is being shown as part of a stack and there is more than 1 brick in that stack
            if ($number_of_bricks > 1) {
                //Show buttons to add new bricks above/below
                $html_output .= '<a class="mp-brick-reorder-bricks" href="' . mp_core_add_query_arg(array('post_type' => 'mp_brick', 'mp-stacks-minimal-admin' => 'true', 'mp_stacks' => $stack_id), admin_url('edit.php')) . '" >' . __('Re-Order Bricks', 'mp_stacks') . '</a>';
            }
        }
    }
    $html_output .= '</div>';
    //Brick BG Div
    $html_output .= '<div class="mp-brick-bg" ' . $extra_brick_bg_attributes . '>';
    $html_output .= '<div class="mp-brick-bg-inner">' . apply_filters('mp_brick_background_content', '', $post_id) . '</div>';
    $html_output .= '</div>';
    //Brick Content Divs
    $html_output .= '<div class="mp-brick-outer"' . $extra_brick_outer_attributes . ' >';
    $html_output .= '<div class="mp-brick-inner">';
    $html_output .= '<div class="mp-brick-content-types">';
    $html_output .= '<div class="mp-brick-content-types-inner">';
    $html_output .= $content_output;
    $html_output .= '</div>';
    $html_output .= '</div>';
    $html_output .= '</div>';
    $html_output .= '</div>';
    $html_output .= '</div>';
    //Return the brick
    return $html_output;
}
Example #2
0
    /**
     * The "Load More" button, "Infinite Scroll", or "Pagination" depending on what the user has decided.
     *
     * @access   public
     * @since    1.0.0
     * @param    Void
     * @param    $post_id Int - The ID of the Brick
     * @param    $load_more_args array - Values needed to output the load more/pagination
     * @return   String - The HTML needed to make the load more button/pagination.
     */
    function mp_stacks_grid_load_more_html_output($load_more_html_output, $post_id, $load_more_args)
    {
        //Assemble args for the load more output
        $default_load_more_args = array('meta_prefix' => NULL, 'total_posts' => 0, 'posts_per_page' => 0, 'paged' => 0, 'post_offset' => 0, 'orderby' => NULL);
        $args = wp_parse_args($load_more_args, $default_load_more_args);
        //Load More Behaviour?
        $load_more_behaviour = mp_core_get_post_meta($post_id, $args['meta_prefix'] . '_load_more_behaviour', 'ajax_load_more');
        //Load More Button Text
        $load_more_button_text = mp_core_get_post_meta($post_id, $args['meta_prefix'] . '_load_more_button_text', __('Load More', 'mp_stacks'));
        //Check spacing (padding) around posts to see if we need to add some specially to our load more button(s)
        $post_spacing = mp_core_get_post_meta($post_id, $args['meta_prefix'] . '_post_spacing', '20');
        $load_more_spacing = $post_spacing == 0 ? 'padding:20px;' : 'padding-bottom:' . $post_spacing . 'px';
        //If we are using the ajax_load_more_style
        if ($load_more_behaviour == 'ajax_load_more') {
            //If there are no more posts in this taxonomy
            if ($args['total_posts'] <= $args['post_offset']) {
                //Return without a button
                return NULL;
            }
            //Button
            return '<div class="mp-stacks-grid-load-more-container" style="' . $load_more_spacing . '"><a mp_stacks_grid_post_id="' . $post_id . '" mp_stacks_grid_brick_offset="' . $args['post_offset'] . '" mp_stacks_grid_orderby="' . $args['orderby'] . '" mp_stacks_grid_loading_text="' . __('Loading...', 'mp_stacks') . '" mp_stacks_grid_ajax_prefix=' . $args['meta_prefix'] . ' class="button mp-stacks-grid-load-more-button">' . $load_more_button_text . '</a>' . mp_stacks_grid_loading_more_animation('none') . '</div>';
        } else {
            if ($load_more_behaviour == 'infinite_scroll') {
                //If there are no more posts in this taxonomy
                if ($args['total_posts'] <= $args['post_offset']) {
                    //Return without a button
                    return NULL;
                }
                //JS for the Load More Button
                $load_more_output = '<div class="mp-stacks-grid-load-more-container" style="' . $load_more_spacing . '"><a mp_stacks_grid_post_id="' . $post_id . '" mp_stacks_grid_brick_offset="' . $args['post_offset'] . '" mp_stacks_grid_orderby="' . $args['orderby'] . '" mp_stacks_grid_loading_text="' . __('Loading...', 'mp_stacks') . '" mp_stacks_grid_ajax_prefix=' . $args['meta_prefix'] . ' class="button mp-stacks-grid-load-more-button">' . $load_more_button_text . '</a>' . mp_stacks_grid_loading_more_animation('none') . '</div>';
                //If we are not doing ajax
                if (!defined('DOING_AJAX')) {
                    //Add the JS Which activates Infinite Scroll using Waypoints
                    $load_more_output .= '<script type="text/javascript">
				jQuery(document).ready(function($){ 
					
					$(\'#mp-brick-' . $post_id . ' .mp-stacks-grid-after\').waypoint(function( direction ) {
												
						if (direction === \'up\') return;
						
						$(\'#mp-brick-' . $post_id . ' .mp-stacks-grid-load-more-button\').trigger(\'click\' );
						
					}, {
						offset: \'bottom-in-view\'
					});
					
				});
				</script>';
                }
                return $load_more_output;
            } else {
                if ($load_more_behaviour == 'pagination') {
                    //Figure out how many pages there based on the count and posts per page
                    $pages = ceil($args['total_posts'] / $args['posts_per_page']);
                    $page_counter = 1;
                    $load_more_output = '<div class="mp-stacks-grid-load-more-container" style="' . $load_more_spacing . '"><nav id="posts-navigation" class="row pagination mp-core-pagination" style="float:none;">
				<ul class="page-numbers">';
                    //Set the base URL based on the current url by removing any brick pagination
                    $base_url = explode('?', mp_core_get_current_url());
                    $url_args = isset($base_url[1]) ? '?' . $base_url[1] : NULL;
                    $base_url = explode('brick/', mp_core_get_current_url());
                    $base_url = $base_url[0];
                    //Create the page number links by looping through each posts per page
                    while ($page_counter <= $pages) {
                        //If we have more than 4 pages (and it is't just 5 where this isn't useful), use show the first 3 page numbers, then show a ..., then show the last page number
                        if ($pages > 4 && $pages != 5) {
                            //If we aren't on the last page or the first page
                            if ($page_counter != $pages && $page_counter != 1) {
                                //If we are more than 3 pages before the current page and we are not on the first or last page
                                if ($page_counter == $args['paged'] - 3) {
                                    //Just show 3 dots
                                    $load_more_output .= '<li><span class="page-numbers dots">...</span></li>';
                                    $page_counter = $page_counter + 1;
                                    continue;
                                }
                                //If we are 3 pages after the current page AND we aren't on the first or last page
                                if ($page_counter == $args['paged'] + 3) {
                                    //Just show 3 dots
                                    $load_more_output .= '<li><span class="page-numbers dots">...</span></li>';
                                    $page_counter = $page_counter + 1;
                                    continue;
                                } else {
                                    if ($page_counter > $args['paged'] + 3) {
                                        $page_counter = $page_counter + 1;
                                        continue;
                                    }
                                }
                            }
                        }
                        if ($page_counter == $args['paged']) {
                            $load_more_output .= '<li><span class="page-numbers current">' . $page_counter . '</span></li>';
                        } else {
                            $load_more_output .= '<li><a class="page-numbers" href="' . $base_url . 'brick/' . $args['brick_slug'] . '/page/' . $page_counter . '/' . $url_args . '">' . $page_counter . '</a></li>';
                        }
                        $page_counter = $page_counter + 1;
                    }
                    $load_more_output .= '</ul>
			</nav></div>';
                    return $load_more_output;
                } else {
                    if ($load_more_behaviour == 'none') {
                        return NULL;
                    }
                }
            }
        }
    }
/**
 * Set the orderby string based on the URL or the Brick's Meta settings.
 *
 * @access   public
 * @since    1.0.0
 * @param    $post_id String - the ID of the Brick where all the meta is saved.
 * @param    $meta_prefix String - the prefix to put before each meta_field key to differentiate it from other plugins. :EG "postgrid"
 * @return   $return_html String The html for the dropdown where the user chooses the orderby options
*/
function mp_stacks_grid_orderby_output($post_id, $meta_prefix)
{
    $return_html = NULL;
    //Before we get to the isotope output, check if there are any orderby options first
    $orderby_options = mp_core_get_post_meta_multiple_checkboxes($post_id, $meta_prefix . '_isotope_orderby_options', array());
    //If orderby options have been set
    if (is_array($orderby_options) && !empty($orderby_options)) {
        //Get any orderby params from the URL that might exist
        $url_order_by = isset($_GET['mp_orderby_' . $post_id]) ? sanitize_text_field($_GET['mp_orderby_' . $post_id]) : NULL;
        //If there isn't a URL orderby param, get the default orderby setting
        $default_orderby = empty($url_order_by) ? mp_core_get_post_meta($post_id, $meta_prefix . '_default_orderby', 'date') : $url_order_by;
        //Add an orderby dropdown menu before the first isotope dropdown
        $return_html .= '<select class="button mp-stacks-grid-orderby-select" id="mp-isotope-sort-select-' . $post_id . '" class="mp-stacks-grid-orderby-select" value="' . $default_orderby . '">';
        //Nicely named orderby options
        $nicelynamed_orderby_options = apply_filters($meta_prefix . '_isotope_orderby_options', array(), $meta_prefix);
        //Add each orderby option to the output
        foreach ($orderby_options as $orderby_option) {
            $return_html .= '<option orderby_url="' . mp_core_add_query_arg(array('mp_orderby_' . $post_id => $orderby_option), mp_core_get_current_url()) . '" value="' . $orderby_option . '" ' . ($default_orderby == $orderby_option ? ' selected' : NULL) . ' >' . __('Order By: ', 'mp_stacks') . $nicelynamed_orderby_options[$orderby_option] . '</option>';
        }
        $return_html .= '</select>';
    }
    return $return_html;
}