Example #1
0
 function prepare_loop_from_entries()
 {
     $this->loop = array();
     if (empty($this->entries) || empty($this->entries->posts)) {
         return;
     }
     $tagTax = "post_tag";
     $date_format = get_option('date_format');
     foreach ($this->entries->posts as $key => $entry) {
         $overlay_img = $custom_url = false;
         $img_size = 'masonry';
         $author = apply_filters('avf_author_name', get_the_author_meta('display_name', $entry->post_author), $entry->post_author);
         $this->loop[$key]['text_before'] = "";
         $this->loop[$key]['text_after'] = "";
         $this->loop[$key]['ID'] = $id = $entry->ID;
         $this->loop[$key]['post_type'] = $entry->post_type;
         $this->loop[$key]['thumb_ID'] = get_post_thumbnail_id($id);
         $this->loop[$key]['the_title'] = get_the_title($id);
         $this->loop[$key]['url'] = get_permalink($id);
         $this->loop[$key]['date'] = "<span class='av-masonry-date meta-color updated'>" . get_the_time($date_format, $id) . "</span>";
         $this->loop[$key]['author'] = "<span class='av-masonry-author meta-color vcard author'><span class='fn'>" . __('by', 'avia_framework') . ' ' . $author . "</span></span>";
         $this->loop[$key]['class'] = get_post_class("av-masonry-entry isotope-item", $id);
         $this->loop[$key]['content'] = $entry->post_excerpt;
         $this->loop[$key]['description'] = !empty($entry->post_content) ? $entry->post_content : $entry->post_excerpt;
         if (empty($this->loop[$key]['content'])) {
             $this->loop[$key]['content'] = avia_backend_truncate($entry->post_content, apply_filters('avf_masonry_excerpt_length', 60), apply_filters('avf_masonry_excerpt_delimiter', " "), "…", true, '');
         }
         //post type specific
         switch ($entry->post_type) {
             case 'post':
                 $post_format = get_post_format($id) ? get_post_format($id) : 'standard';
                 $this->loop[$key] = apply_filters('post-format-' . $post_format, $this->loop[$key]);
                 $this->loop[$key]['text_after'] .= $this->loop[$key]['date'];
                 $this->loop[$key]['text_after'] .= '<span class="av-masonry-text-sep text-sep-author">/</span>';
                 $this->loop[$key]['text_after'] .= $this->loop[$key]['author'];
                 switch ($post_format) {
                     case 'quote':
                     case 'link':
                     case 'image':
                     case 'gallery':
                         if (!$this->loop[$key]['thumb_ID']) {
                             $this->loop[$key]['text_before'] = av_icon_display($post_format);
                         }
                         break;
                     case 'audio':
                     case 'video':
                         if (!$this->loop[$key]['thumb_ID']) {
                             $this->loop[$key]['text_before'] = av_icon_display($post_format);
                         } else {
                             $this->loop[$key]['text_before'] = av_icon_display($post_format, 'av-masonry-media');
                         }
                         break;
                 }
                 break;
             case 'portfolio':
                 //set portfolio breadcrumb navigation
                 if ($this->atts['set_breadcrumb'] && is_page()) {
                     $_SESSION["avia_{$entry->post_type}"] = get_the_ID();
                 }
                 //check if the user has set up a custom link
                 if (!post_password_required($id)) {
                     $custom_link = get_post_meta($id, '_portfolio_custom_link', true) != "" ? get_post_meta($id, '_portfolio_custom_link_url', true) : false;
                     if ($custom_link) {
                         $this->loop[$key]['url'] = $custom_link;
                     }
                 }
                 break;
             case 'attachment':
                 $custom_url = get_post_meta($id, 'av-custom-link', true);
                 $this->loop[$key]['thumb_ID'] = $id;
                 $this->loop[$key]['content'] = $entry->post_excerpt;
                 if ($custom_url) {
                     $this->loop[$key]['url'] = $custom_url;
                 } else {
                     $this->loop[$key]['url'] = wp_get_attachment_image_src($id, apply_filters('avf_avia_builder_masonry_lightbox_img_size', 'large'));
                     $this->loop[$key]['url'] = reset($this->loop[$key]['url']);
                 }
                 break;
             case 'product':
                 //check if woocommerce is enabled in the first place so we can use woocommerce functions
                 if (function_exists('avia_woocommerce_enabled') && avia_woocommerce_enabled()) {
                     $tagTax = "product_tag";
                     $product = get_product($id);
                     $overlay_img = avia_woocommerce_gallery_first_thumbnail($id, $img_size, true);
                     $this->loop[$key]['text_after'] .= '<span class="av-masonry-price price">' . $product->get_price_html() . "</span>";
                     if ($product->is_on_sale()) {
                         $this->loop[$key]['text_after'] .= '<span class="onsale">' . __('Sale!', 'avia_framework') . '</span>';
                     }
                 }
                 break;
         }
         //check if post is password protected
         if (post_password_required($id)) {
             $this->loop[$key]['content'] = "";
             $this->loop[$key]['class'][] = "entry-protected";
             $this->loop[$key]['thumb_ID'] = "";
             $this->loop[$key]['text_before'] = av_icon_display('closed');
             $this->loop[$key]['text_after'] = $this->loop[$key]['date'];
         }
         //set the html tags. depending on the link settings use either an a tag or a div tag
         if (!empty($this->atts['container_links']) || !empty($custom_url)) {
             $this->loop[$key]['html_tags'] = array('a href="' . $this->loop[$key]['url'] . '"', 'a');
             //opening and closing tag for the masonry container
         } else {
             $this->loop[$key]['html_tags'] = array('div', 'div');
         }
         //get post tags
         $this->loop[$key]['tags'] = wp_get_post_terms($id, $tagTax, array('fields' => 'slugs'));
         //check if the image got landscape as well as portrait class applied. in that case use a bigger image size
         if (strlen($this->ratio_check_by_tag($this->loop[$key]['tags'])) > 20) {
             $img_size = 'extra_large';
         }
         //get attachment data
         $this->loop[$key]['attachment'] = !empty($this->loop[$key]['thumb_ID']) ? wp_get_attachment_image_src($this->loop[$key]['thumb_ID'], $img_size) : "";
         //get overlay attachment in case the overlay is set
         $this->loop[$key]['attachment_overlay'] = !empty($overlay_img) ? wp_get_attachment_image_src($overlay_img, $img_size) : "";
         //apply filter for other post types, in case we want to use them and display additional/different information
         $this->loop[$key] = apply_filters('avf_masonry_loop_prepare', $this->loop[$key], $this->entries);
     }
 }
Example #2
0
        return true;
    }
    return false;
}
global $avia_config;
//product thumbnails
$avia_config['imgSize']['shop_thumbnail'] = array('width' => 120, 'height' => 120);
$avia_config['imgSize']['shop_catalog'] = array('width' => 450, 'height' => 450);
$avia_config['imgSize']['shop_single'] = array('width' => 450, 'height' => 999, 'crop' => false);
avia_backend_add_thumbnail_size($avia_config);
include 'admin-options.php';
include 'admin-import.php';
include 'woocommerce-mod-css-dynamic.php';
add_theme_support('woocommerce');
//check if the plugin is enabled, otherwise stop the script
if (!avia_woocommerce_enabled()) {
    return false;
}
//register my own styles, remove wootheme stylesheet
if (!is_admin()) {
    add_action('init', 'avia_woocommerce_register_assets');
}
function avia_woocommerce_register_assets()
{
    wp_enqueue_style('avia-woocommerce-css', AVIA_BASE_URL . 'config-woocommerce/woocommerce-mod.css');
    wp_enqueue_script('avia-woocommerce-js', AVIA_BASE_URL . 'config-woocommerce/woocommerce-mod.js', array('jquery'), 1, true);
}
global $woocommerce;
if (version_compare($woocommerce->version, "2.1", "<")) {
    define('WOOCOMMERCE_USE_CSS', false);
} else {
Example #3
0
 /**
  * This function creates the html code necessary for a woocommerce shop section. It uses the woocommerce shop loop to do that
  *
  * @param array $element is an array with all the data necessary for creating the html code (it contains the element data and the saved values for the element)
  * @return string $output the string returned contains the html code generated within the method
  */
 function shop($element)
 {
     $output = "";
     //check if the plugin is enabled
     if (!avia_woocommerce_enabled()) {
         $url = network_site_url('wp-admin/plugin-install.php?tab=search&type=term&s=WooCommerce&plugin-search-input=Search+Plugins');
         $output = "<p><strong>You need to install and activate the <a href='{$url}'>WooCommerce Shop Plugin</a> to display Products</strong></p>";
         return $output;
     }
     extract($element['saved_value'][0]);
     global $avia_config, $more, $woocommerce_loop;
     if ($shop_columns == 5 && strpos($avia_config['layout'], 'dual') !== false) {
         $shop_columns = 4;
     }
     if ($shop_text == 'yes') {
         $avia_config['shop_overview_excerpt'] = 'active';
     }
     $woocommerce_loop['columns'] = $avia_config['shop_overview_column'] = $shop_columns;
     $order = get_option('woocommerce_default_catalog_orderby');
     if (!$order) {
         $order = "menu_order";
     }
     $avia_config['new_query'] = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, "paged" => get_query_var('paged'), 'posts_per_page' => $shop_item_count, 'orderby' => $order, 'order' => 'desc', 'meta_query' => array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
     if (empty($shop_cats_dynamic) || $shop_cats_dynamic == 'null') {
         $avia_config['new_query']['post_type'] = "product";
     } else {
         $avia_config['new_query']['tax_query'] = array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => explode(',', $shop_cats_dynamic), 'operator' => 'IN'));
     }
     query_posts($avia_config['new_query']);
     ob_start();
     if (have_posts()) {
         do_action('woocommerce_before_shop_loop');
         echo '<ul class="products">';
         woocommerce_product_subcategories();
         while (have_posts()) {
             the_post();
             woocommerce_get_template_part('content', 'product');
         }
         // end of the loop.
         echo '</ul>';
         do_action('woocommerce_after_shop_loop');
     } else {
         if (!woocommerce_product_subcategories(array('before' => '<ul class="products">', 'after' => '</ul>'))) {
             echo "<p>" . __('No products found which match your selection.', 'woocommerce') . "</p>";
         }
     }
     echo '<div class="clear"></div>';
     $products = ob_get_clean();
     $output .= "<div class='container_wrap " . $avia_config['layout'] . " template-shop shop_columns_" . $avia_config['shop_overview_column'] . "'>";
     $output .= "<div class='template-shop content shop_slider_{$shop_slider}' data-interval='{$shop_autorotate}'>";
     $output .= $products;
     if ($shop_pagination == 'yes') {
         $output .= avia_pagination();
     }
     $output .= "</div>";
     $output .= "</div>";
     wp_reset_query();
     return $output;
 }