Example #1
0
 /**
  * Include font from google. Accepts unlimited
  * amount of font arguments.
  *
  * @since 2.0.0
  */
 function themeblvd_include_google_fonts()
 {
     $fonts = func_get_args();
     $used = array();
     if (!empty($fonts)) {
         // Before including files, determine if SSL is being
         // used because if we include an external file without https
         // on a secure server, they'll get an error.
         $protocol = is_ssl() ? 'https://' : 'http://';
         // Include each font file from google.
         foreach ($fonts as $font) {
             if ($font['face'] == 'google' && $font['google']) {
                 if (in_array($font['google'], $used)) {
                     // Skip duplicate
                     continue;
                 }
                 $used[] = $font['google'];
                 $name = themeblvd_remove_trailing_char($font['google']);
                 $name = str_replace(' ', '+', $name);
                 printf('<link href="%sfonts.googleapis.com/css?family=%s" rel="stylesheet" type="text/css">' . "\n", $protocol, $name);
             }
         }
     }
 }
 /**
  * Make any needed modifications to the main query
  * via pre_get_posts for the homepage or frontpage
  *
  * @since 2.3.0
  *
  * @param WP_Query $q Current WP_Query object at the time of pre_get_posts
  */
 public function pre_get_posts($q)
 {
     if (!$q->is_main_query() || !$q->is_home() && !$q->is_page() && !$q->is_archive()) {
         return;
     }
     // Static frontpage
     if ($q->is_page() && get_option('show_on_front') == 'page' && get_option('page_on_front') == $q->get('page_id')) {
         $templates = apply_filters('themeblvd_paginated_templates', array('template_list.php', 'template_list.php', 'template_builder.php'));
         $template = get_post_meta($q->get('page_id'), '_wp_page_template', true);
         if (in_array($template, $templates) && isset($q->query['paged'])) {
             $q->set('paged', $q->query['paged']);
         }
     }
     // Adjust posts_per_page if framework is in grid mode
     if ($q->is_archive() || $this->is_blog($q)) {
         // Check to make sure we're in grid mode
         if (themeblvd_is_grid_mode()) {
             $key = 'archive';
             if ($this->is_blog($q)) {
                 $key = 'index';
             }
             $columns = themeblvd_get_option("{$key}_grid_columns");
             if (!$columns) {
                 $columns = apply_filters('themeblvd_default_grid_columns', 3);
             }
             $rows = themeblvd_get_option("{$key}_grid_rows");
             if (!$rows) {
                 $rows = apply_filters('themeblvd_default_grid_rows', 4);
             }
             // Posts per page = $columns x $rows
             $q->set('posts_per_page', $columns * $rows);
         }
     }
     // Exclude any categories from posts page
     if ($this->is_blog($q)) {
         $cat = '';
         if (themeblvd_is_grid_mode()) {
             $exclude = themeblvd_get_option('grid_categories');
         } else {
             $exclude = themeblvd_get_option('blog_categories');
         }
         if ($exclude) {
             foreach ($exclude as $key => $value) {
                 if ($value) {
                     $cat .= sprintf('-%s,', $key);
                 }
             }
         }
         if ($cat) {
             $cat = themeblvd_remove_trailing_char($cat, ',');
             $q->set('cat', $cat);
         }
     }
     // Apply pagination fix when homepage custom layout
     // set over home "posts page"
     if (defined('TB_BUILDER_PLUGIN_VERSION') && $q->is_home() && 'custom_layout' == themeblvd_get_option('homepage_content')) {
         // Layout info
         $kayout_name = themeblvd_get_option('homepage_custom_layout');
         $layout_post_id = themeblvd_post_id_by_name($kayout_name, 'tb_layout');
         if ($layout_post_id) {
             $elements = get_post_meta($layout_post_id, 'elements', true);
         }
         // Loop through elements and look for that single
         // paginated element (there can only be one in a layout).
         if (!empty($elements) && is_array($elements)) {
             foreach ($elements as $area) {
                 if (!empty($area) && is_array($area)) {
                     foreach ($area as $element) {
                         switch ($element['type']) {
                             case 'post_grid_paginated':
                                 if (!empty($element['options']['rows']) && !empty($element['options']['columns'])) {
                                     $posts_per_page = intval($element['options']['rows']) * intval($element['options']['columns']);
                                 }
                                 $q->set('posts_per_page', $posts_per_page);
                                 break;
                             case 'post_list_paginated':
                                 if (isset($element['options']['source']) && 'query' == $element['options']['source']) {
                                     if (!empty($element['options']['query'])) {
                                         $custom_q = wp_parse_args(htmlspecialchars_decode($element['options']['query']));
                                     }
                                     if (isset($custom_q['posts_per_page'])) {
                                         $q->set('posts_per_page', $custom_q['posts_per_page']);
                                     }
                                 } else {
                                     if (!empty($element['options']['posts_per_page'])) {
                                         $q->set('posts_per_page', $element['options']['posts_per_page']);
                                     }
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
     do_action('themeblvd_pre_get_posts', $q, $this);
 }
Example #3
0
/**
 * Take a piece of markup and wrap it in a link to a lightbox.
 *
 * @since 2.3.0
 *
 * @param $args array Arguments for lightbox link
 * @return $output string Final HTML to output
 */
function themeblvd_get_link_to_lightbox($args)
{
    $defaults = array('item' => themeblvd_get_local('link_to_lightbox'), 'link' => '', 'title' => '', 'type' => '', 'class' => '', 'props' => array(), 'addon' => '', 'gallery' => false);
    $args = wp_parse_args($args, $defaults);
    // Item markup to wrap link around
    $item = $args['item'];
    // Start building link properties
    $props = array('href' => $args['link'], 'title' => $args['title'], 'class' => '');
    // Fix for youtu.be links
    if (strpos($props['href'], 'http://youtu.be/') !== false) {
        $props['href'] = str_replace('http://youtu.be/', 'http://youtube.com/watch?v=', $props['href']);
    }
    // Lightbox type
    $types = array('image', 'iframe', 'inline', 'ajax');
    $type = $args['type'];
    if (!in_array($type, $types)) {
        // Auto lightbox type detection
        if (strpos($props['href'], 'youtube.com') !== false || strpos($props['href'], 'vimeo.com') !== false || strpos($props['href'], 'maps.google.com') !== false) {
            $type = 'iframe';
        } else {
            if (strpos($props['href'], '#') === 0) {
                $type = 'inline';
            } else {
                $parsed_url = parse_url($props['href']);
                $filetype = wp_check_filetype($parsed_url['path']);
                // Link to image file?
                if (substr($filetype['type'], 0, 5) == 'image') {
                    $type = 'image';
                }
            }
        }
    }
    // CSS classes
    $class = array('themeblvd-lightbox', "mfp-{$type}");
    if ('iframe' == $type) {
        $class[] = 'lightbox-iframe';
        // Enables framework's separate JS for iframe video handling in non-galleries
    }
    $user_class = $args['class'];
    if (!is_array($args['class'])) {
        $user_class = explode(' ', $args['class']);
    }
    $class = array_merge($class, $user_class);
    $class = apply_filters('themeblvd_lightbox_class', $class, $args, $type, $item);
    // Filter while still an array
    $props['class'] = implode(' ', $class);
    // Add user any additional properties passed in
    if (is_array($args['props'])) {
        $props = array_merge($props, $args['props']);
    }
    // Extend link properties
    $props = apply_filters('themeblvd_lightbox_props', $props, $args, $type, $item, $class);
    // Use properties array to build anchor tag
    $output = '<a ';
    foreach ($props as $key => $value) {
        $output .= "{$key}=\"{$value}\" ";
    }
    $output = themeblvd_remove_trailing_char($output, ' ');
    // Manual addon
    if ($args['addon']) {
        $output .= ' ' . $args['addon'];
    }
    // Finish link
    $output .= sprintf('>%s</a>', $item);
    return apply_filters('themeblvd_link_to_lightbox', $output, $args, $props, $type, $item, $class);
}
Example #4
0
/**
 * Setup arguments to pass into get_posts()
 *
 * @since 2.0.0
 *
 * @param array $options All options for query string
 * @param string $type Type of posts setup, grid or list
 * @param boolean $slider Whether or no this is a post list/grid slider (NOT auto slider)
 * @return array $args Arguments to get passed into get_posts()
 */
function themeblvd_get_posts_args($options, $type, $slider = false)
{
    // Is there a query source? (i.e. category, tag, query)
    $source = '';
    if (!empty($options['source'])) {
        $source = $options['source'];
    }
    // Custom query
    if ('query' == $source && isset($options['query']) || !$source && !empty($options['query'])) {
        // Convert string to query array
        $query = wp_parse_args(htmlspecialchars_decode($options['query']));
        // Force posts per page on grids
        if ('grid' == $type && !$slider && apply_filters('themeblvd_force_grid_posts_per_page', true)) {
            if (!empty($options['rows']) && !empty($options['columns'])) {
                $query['numberposts'] = $options['rows'] * $options['columns'];
            }
        }
    }
    // If no custom query, let's build it.
    if (!isset($query)) {
        // Start $query
        $query = array('suppress_filters' => false);
        // Number of posts
        if ($type == 'grid' && !$slider) {
            if (!empty($options['rows']) && !empty($options['columns'])) {
                $query['numberposts'] = intval($options['rows']) * intval($options['columns']);
            }
        } else {
            if (!empty($options['numberposts'])) {
                $query['numberposts'] = intval($options['numberposts']);
            }
        }
        if (empty($query['numberposts'])) {
            $query['numberposts'] = -1;
        }
        // Categories
        if ('category' == $source || !$source) {
            if ('auto_slider' == $type) {
                // The "Post Slider" element
                if (!empty($options['category'])) {
                    $query['category_name'] = $options['category'];
                }
            } else {
                if (!empty($options['cat'])) {
                    // Category override option #1 -- cat
                    $query['cat'] = $options['cat'];
                } elseif (!empty($options['category_name'])) {
                    // Category override option #2 -- category_name
                    $query['category_name'] = $options['category_name'];
                } elseif (!empty($options['categories']) && !$options['categories']['all']) {
                    unset($options['categories']['all']);
                    $categories = '';
                    foreach ($options['categories'] as $category => $include) {
                        if ($include) {
                            $current_category = get_term_by('slug', $category, 'category');
                            $categories .= $current_category->term_id . ',';
                        }
                    }
                    if ($categories) {
                        $categories = themeblvd_remove_trailing_char($categories, ',');
                        $query['cat'] = $categories;
                    }
                }
            }
        }
        // Tags
        if ('tag' == $source || !$source) {
            if (!empty($options['tag'])) {
                $query['tag'] = $options['tag'];
            }
        }
        // Additional args
        if (!empty($options['orderby'])) {
            $query['orderby'] = $options['orderby'];
        }
        if (!empty($options['order'])) {
            $query['order'] = $options['order'];
        }
        if (!empty($options['offset'])) {
            $query['offset'] = intval($options['offset']);
        }
    }
    return apply_filters('themeblvd_get_posts_args', $query, $options, $type, $slider);
}