/**
  * widget function.
  *
  * @see WP_Widget
  * @access public
  *
  * @param array $args
  * @param array $instance
  *
  * @return void
  */
 public function widget($args, $instance)
 {
     // Extract the arguments
     extract($args);
     $title = isset($instance['title']) ? apply_filters('widget_title', $instance['title'], $instance, $this->id_base) : __('Featured Downloads', 'download-monitor');
     $posts_per_page = isset($instance['posts_per_page']) ? absint($instance['posts_per_page']) : 10;
     $format = isset($instance['format']) ? sanitize_title($instance['format']) : '';
     $orderby = isset($instance['orderby']) ? $instance['orderby'] : 'title';
     $order = isset($instance['order']) ? $instance['order'] : 'ASC';
     $featured = isset($instance['featured']) ? $instance['featured'] : 'no';
     $members_only = isset($instance['members_only']) ? $instance['members_only'] : 'no';
     $args = array('post_status' => 'publish', 'post_type' => 'dlm_download', 'no_found_rows' => 1, 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'order' => $order, 'meta_query' => array(), 'tax_query' => array());
     if ($orderby == 'download_count') {
         $args['orderby'] = 'meta_value_num';
         $args['meta_key'] = '_download_count';
     }
     if ($featured == 'yes') {
         $args['meta_query'][] = array('key' => '_featured', 'value' => 'yes');
     }
     if ($members_only == 'yes') {
         $args['meta_query'][] = array('key' => '_members_only', 'value' => 'yes');
     }
     $r = new WP_Query($args);
     if ($r->have_posts()) {
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         echo apply_filters('dlm_widget_downloads_list_start', '<ul class="dlm-downloads">');
         // Template handler
         $template_handler = new DLM_Template_Handler();
         while ($r->have_posts()) {
             $r->the_post();
             echo apply_filters('dlm_widget_downloads_list_item_start', '<li>');
             $template_handler->get_template_part('content-download', $format, '', array('dlm_download' => new DLM_Download(get_the_ID())));
             echo apply_filters('dlm_widget_downloads_list_item_end', '</li>');
         }
         echo apply_filters('dlm_widget_downloads_list_end', '</ul>');
         echo $after_widget;
     }
 }
Пример #2
0
<?php

global $dlm_page_addon;
?>
<div class="download_category download_group">
	<h3><a href="<?php 
echo $dlm_page_addon->get_category_link($category);
?>
"><?php 
echo $category->name;
?>
</a></h3>
	<ul>
		<?php 
while ($downloads->have_posts()) {
    $downloads->the_post();
    ?>

			<li><?php 
    $template_handler = new DLM_Template_Handler();
    $template_handler->get_template_part('content-download', $format, $dlm_page_addon->plugin_path() . 'templates/');
    ?>
</li>

		<?php 
}
?>
	</ul>
</div>
Пример #3
0
 /**
  * get_template_part function.
  *
  * @deprecated 1.6.0
  *
  * @access public
  *
  * @param mixed $slug
  * @param string $name (default: '')
  *
  * @return void
  */
 public function get_template_part($slug, $name = '', $custom_dir = '')
 {
     // Deprecated
     DLM_Debug_Logger::deprecated(__METHOD__);
     // Load template part
     $template_handler = new DLM_Template_Handler();
     $template_handler->get_template_part($slug, $name, $custom_dir);
 }
 /**
  * The dlm_no_access shortcode callback
  *
  * @param array $atts
  *
  * @return string
  */
 public function no_access_page($atts)
 {
     global $wp;
     // atts
     $atts = shortcode_atts(array('show_message' => 'true'), $atts);
     // start buffer
     ob_start();
     // show_message must be a bool
     $atts['show_message'] = 'true' === $atts['show_message'];
     // return empty string if download-id is not set
     if (!isset($wp->query_vars['download-id'])) {
         return '';
     }
     // template handler
     $template_handler = new DLM_Template_Handler();
     // load no access template
     $template_handler->get_template_part('no-access', '', '', array('download' => new DLM_Download($wp->query_vars['download-id']), 'no_access_message' => $atts['show_message'] ? wp_kses_post(get_option('dlm_no_access_error', '')) : ''));
     // set new content
     $content = ob_get_clean();
     return $content;
 }
    /**
     * downloads function.
     *
     * @access public
     *
     * @param mixed $atts
     *
     * @return void
     */
    public function downloads($atts)
    {
        global $dlm_max_num_pages;
        extract(shortcode_atts(array('per_page' => '-1', 'orderby' => 'date', 'order' => 'desc', 'include' => '', 'exclude' => '', 'offset' => '', 'category' => '', 'category_include_children' => true, 'tag' => '', 'featured' => false, 'members_only' => false, 'template' => dlm_get_default_download_template(), 'loop_start' => '<ul class="dlm-downloads">', 'loop_end' => '</ul>', 'before' => '<li>', 'after' => '</li>', 'paginate' => false), $atts));
        $post__in = !empty($include) ? explode(',', $include) : '';
        $post__not_in = !empty($exclude) ? explode(',', $exclude) : '';
        $order = strtoupper($order);
        $meta_key = '';
        switch ($orderby) {
            case 'title':
            case 'rand':
            case 'ID':
            case 'date':
            case 'modified':
            case 'post__in':
                $orderby = $orderby;
                break;
            case 'id':
                $orderby = 'ID';
                break;
            case 'hits':
            case 'count':
            case 'download_count':
                $orderby = 'meta_value_num';
                $meta_key = '_download_count';
                break;
            default:
                $orderby = 'title';
                break;
        }
        $args = array('post_type' => 'dlm_download', 'posts_per_page' => $per_page, 'offset' => $paginate ? (max(1, get_query_var('paged')) - 1) * $per_page : $offset, 'post_status' => 'publish', 'orderby' => $orderby, 'order' => $order, 'meta_key' => $meta_key, 'post__in' => $post__in, 'post__not_in' => $post__not_in, 'meta_query' => array());
        if ($category || $tag) {
            $args['tax_query'] = array('relation' => 'AND');
            $tags = array_filter(explode(',', $tag));
            // check if we include category children
            $include_children = $category_include_children === 'true' || $category_include_children === true;
            if (!empty($category)) {
                if (preg_match('/\\+/', $category)) {
                    // categories with AND
                    // string to array
                    $categories = array_filter(explode('+', $category));
                    // check if explode had results
                    if (!empty($categories)) {
                        foreach ($categories as $category) {
                            $args['tax_query'][] = array('taxonomy' => 'dlm_download_category', 'field' => 'slug', 'terms' => $category, 'include_children' => $include_children);
                        }
                    }
                } else {
                    // categories with OR
                    // string to array
                    $categories = array_filter(explode(',', $category));
                    // check if explode had results
                    if (!empty($categories)) {
                        $args['tax_query'][] = array('taxonomy' => 'dlm_download_category', 'field' => 'slug', 'terms' => $categories, 'include_children' => $include_children);
                    }
                }
            }
            if (!empty($tags)) {
                $args['tax_query'][] = array('taxonomy' => 'dlm_download_tag', 'field' => 'slug', 'terms' => $tags);
            }
        }
        if ($featured === 'true' || $featured === true) {
            $args['meta_query'][] = array('key' => '_featured', 'value' => 'yes');
        }
        if ($members_only === 'true' || $members_only === true) {
            $args['meta_query'][] = array('key' => '_members_only', 'value' => 'yes');
        }
        ob_start();
        // Allow filtering of arguments
        $args = apply_filters('dlm_shortcode_downloads_args', $args);
        $downloads = new WP_Query($args);
        $dlm_max_num_pages = $downloads->max_num_pages;
        // Template handler
        $template_handler = new DLM_Template_Handler();
        if ($downloads->have_posts()) {
            ?>

			<?php 
            echo html_entity_decode($loop_start);
            ?>

			<?php 
            while ($downloads->have_posts()) {
                $downloads->the_post();
                ?>

				<?php 
                echo html_entity_decode($before);
                ?>

				<?php 
                $template_handler->get_template_part('content-download', $template, '', array('dlm_download' => new DLM_Download(get_the_ID())));
                ?>

				<?php 
                echo html_entity_decode($after);
                ?>

			<?php 
            }
            // end of the loop.
            ?>

			<?php 
            echo html_entity_decode($loop_end);
            ?>

			<?php 
            if ($paginate) {
                $template_handler->get_template_part('pagination', '');
            }
            ?>

		<?php 
        }
        wp_reset_postdata();
        return ob_get_clean();
    }