function id_projectGrid($attrs)
{
    ob_start();
    if (isset($attrs['columns'])) {
        $wide = $attrs['columns'];
    } else {
        $wide = 3;
    }
    $width = 90 / $wide;
    $margin = 10 / ($wide - 1);
    if (isset($attrs['max'])) {
        $max = $attrs['max'];
    } else {
        $max = null;
    }
    // project category
    if (isset($attrs['category'])) {
        $category = $attrs['category'];
        $args = array('post_type' => 'ignition_product', 'tax_query' => array(array('taxonomy' => 'project_category', 'field' => 'id', 'terms' => $category)));
    } else {
        // in case category isn't defined, query args must contain post type
        $args['post_type'] = 'ignition_product';
    }
    if (isset($max)) {
        $args['posts_per_page'] = $max;
    }
    // --> Custom args - START
    // orderby possible values - days_left, percent_raised, funds_raised, rand, title, date (default)
    if (isset($attrs['orderby'])) {
        if ($attrs['orderby'] == 'days_left') {
            $args['orderby'] = 'meta_value_num';
            $args['meta_key'] = 'ign_days_left';
        } else {
            if ($attrs['orderby'] == 'percent_raised') {
                $args['orderby'] = 'meta_value_num';
                $args['meta_key'] = 'ign_percent_raised';
            } else {
                if ($attrs['orderby'] == 'funds_raised') {
                    $args['orderby'] = 'meta_value_num';
                    $args['meta_key'] = 'ign_fund_raised';
                } else {
                    // reserved for later use
                    $args['orderby'] = $attrs['orderby'];
                }
            }
        }
    }
    // order possible values = ASC, DESC (default)
    if (isset($attrs['order'])) {
        $args['order'] = $attrs['order'];
    }
    // author (single name)
    if (isset($attrs['author'])) {
        $args['author_name'] = $attrs['author'];
    }
    // --> Custom args - END
    // moved this block before the query call
    require 'languages/text_variables.php';
    $custom = false;
    if (isset($attrs['deck'])) {
        $deck_id = $attrs['deck'];
        $settings = Deck::get_deck_attrs($deck_id);
        if (!empty($settings)) {
            $attrs = unserialize($settings->attributes);
            $custom = true;
        }
    }
    // start the actual query, which will also output decks
    $posts = get_posts($args);
    $project_ids = array();
    echo '<div class="ignitiondeck"><div class="grid_wrap" data-wide="' . $wide . '">';
    $i = 1;
    foreach ($posts as $post) {
        $post_id = $post->ID;
        $project_id = get_post_meta($post_id, 'ign_project_id', true);
        // no more "pass" checks are required, because the query gets all proper projects in proper order and settings
        $deck = new Deck($project_id);
        $mini_deck = $deck->mini_deck();
        $post_id = $deck->get_project_postid();
        $status = get_post_status($post_id);
        $custom = apply_filters('idcf_custom_deck', $custom, $post_id);
        $attrs = apply_filters('idcf_deck_attrs', isset($attrs) ? $attrs : null, $post_id);
        if (strtoupper($status) == 'PUBLISH') {
            $settings = getSettings();
            echo '<div class="grid_item" style="float: left; margin: 0 ' . $margin . '% ' . $margin . '% 0; width: ' . $width . '%;">';
            include 'templates/_miniWidget.php';
            echo '</div>';
            $i++;
        }
    }
    // end with query and continue with original code
    echo '</div></div>';
    echo '<br style="clear: both"/>';
    $grid = ob_get_contents();
    ob_end_clean();
    return $grid;
}
 function html($widget, $params, $sidebar)
 {
     global $post, $wpdb;
     $show_mini = false;
     $page_project_id = 0;
     $custom = false;
     // Condition to store the product_id, if the page currently being visited is the project page or some other
     if (isset($post)) {
         if ($post->post_type == 'ignition_product') {
             $post_id = $post->ID;
             $page_project_id = get_post_meta($post_id, 'ign_project_id', true);
             //$page_project_id = projectPageof($post->ID, $params['product_id']);
         }
         // We have three conditions now
         // 1.	Show Mini widget only, on all pages
         // 2.	Show Full widget on all pages
         // 3.	Show Mini widget on all pages except the project page
         if (isset($params['widget_options'])) {
             if ($params['widget_options'] == "miniwidget") {
                 $show_mini = true;
             } else {
                 if ($params['widget_options'] == "fullwidget") {
                     $show_mini = false;
                 } else {
                     if ($params['widget_options'] == "miniallpages" && $page_project_id > 0) {
                         //2nd condition means it is a project page, containing some non-zero project_id
                         $show_mini = false;
                     } else {
                         $show_mini = true;
                     }
                 }
             }
         } else {
             $show_mini = true;
         }
         if (isset($params['deck_id']) && $params['deck_id'] > 0) {
             $deck_id = $params['deck_id'];
             $settings = Deck::get_deck_attrs($deck_id);
             if (!empty($settings)) {
                 $attrs = unserialize($settings->attributes);
                 $custom = true;
             }
         }
     }
     // If it's a project page, use the post_id to get the product, else use the product_id in $params
     if ($page_project_id > 0) {
         $project_id = $page_project_id;
     } else {
         $project_id = $params['product_id'];
     }
     $deck = new Deck($project_id);
     if ($show_mini == true) {
         $mini_deck = $deck->mini_deck();
         $post_id = $mini_deck->post_id;
     } else {
         $the_deck = $deck->the_deck();
         $post_id = $deck->post_id;
     }
     $custom = apply_filters('idcf_custom_deck', $custom, $post_id);
     $attrs = apply_filters('idcf_deck_attrs', isset($attrs) ? $attrs : null, $post_id);
     $widget_before = '';
     $widget_after = '';
     $mini_widget_before = '';
     $mini_widget_after = '';
     // Calling the HTML code
     ob_start();
     require ID_PATH . 'languages/text_variables.php';
     include ID_PATH . 'templates/_igWidget.php';
     $widget = ob_get_contents();
     ob_end_clean();
     if ($show_mini) {
         echo apply_filters('id_mini_widget', $widget);
     } else {
         echo apply_filters('id_widget', $widget);
     }
 }
function get_deck_attrs()
{
    global $wpdb;
    if (isset($_POST['Deck'])) {
        $deck_id = absint($_POST['Deck']);
        if ($deck_id > 0) {
            $settings = Deck::get_deck_attrs($deck_id);
            $attrs = unserialize($settings->attributes);
            print_r(json_encode($attrs));
        }
    }
    exit;
}