Example #1
0
        if ($page > 1) {
            $output .= '<a href="' . download_page_link($page - 1) . '" title="' . __('&laquo;', 'nqd-store') . '">&#8201;' . __('&laquo;', 'nqd-store') . '&#8201;</a>';
        }
        for ($i = $start_page; $i <= $end_page; $i++) {
            if ($i == $page) {
                $output .= '<span class="current">&#8201;' . number_format_i18n($i) . '&#8201;</span>';
            } else {
                $output .= '<a href="' . download_page_link($i) . '" title="' . number_format_i18n($i) . '">&#8201;' . number_format_i18n($i) . '&#8201;</a>';
            }
        }
        if (empty($page) || $page + 1 <= $max_page) {
            $output .= '<a href="' . download_page_link($page + 1) . '" title="' . __('&raquo;', 'nqd-store') . '">&#8201;' . __('&raquo;', 'nqd-store') . '&#8201;</a>';
        }
        if ($end_page < $max_page) {
            $output .= '<span class="extend">...</span>';
            $output .= '<a href="' . download_page_link($max_page) . '" title="' . __('Last &raquo;', 'nqd-store') . '">&#8201;' . __('Last &raquo;', 'nqd-store') . '&#8201;</a>';
        }
        $output .= '</div>';
    }
    $post_ID = getPostIDFilterStar($offset, $perpage);
    ?>
						<?php 
    foreach ($post_ID as $post_item) {
        global $post;
        $post = get_post($post_item->post_id);
        setup_postdata($post);
        ?>
						<?php 
        get_template_part('content', get_post_format());
        ?>
						<?php 
Example #2
0
function downloads_page($category_id = 0)
{
    global $wpdb, $user_ID;
    // Variables
    $category_id = intval($category_id);
    $category = !empty($_GET['dl_cat']) ? intval($_GET['dl_cat']) : 0;
    $page = !empty($_GET['dl_page']) ? intval($_GET['dl_page']) : 0;
    $search_word = !empty($_GET['dl_search']) ? strip_tags(addslashes(trim($_GET['dl_search']))) : '';
    $search_words_array = array();
    $search = stripslashes($search_word);
    $download_categories = get_option('download_categories');
    $download_categories[0] = __('total', 'wp-downloadmanager');
    $category_stats = array();
    $total_stats = array('files' => 0, 'size' => 0, 'hits' => 0);
    $file_sort = get_option('download_sort');
    $file_extensions_images = file_extension_images();
    $current_user = wp_get_current_user();
    // If There Is Category Set
    $category_sql = '';
    if ($category == 0 && $category_id > 0) {
        $category = $category_id;
    }
    if ($category > 0) {
        $category_sql = "AND file_category = {$category}";
    }
    // If There Is A Search Term
    $search_sql = '';
    if (!empty($search)) {
        $search_words_array = explode(' ', $search_word);
        foreach ($search_words_array as $search_word_array) {
            $search_sql .= " AND ((file_name LIKE('%{$search_word_array}%') OR file_des LIKE ('%{$search_word_array}%')))";
        }
    }
    // Calculate Categories And Total Stats
    $categories = $wpdb->get_results("SELECT file_category, COUNT(file_id) as category_files, SUM(file_size) category_size, SUM(file_hits) as category_hits FROM {$wpdb->downloads} WHERE 1=1 {$category_sql} {$search_sql} AND file_permission != -2 GROUP BY file_category");
    if ($categories) {
        foreach ($categories as $cat) {
            $cat_id = intval($cat->file_category);
            $category_stats[$cat_id]['files'] = $cat->category_files;
            $category_stats[$cat_id]['hits'] = $cat->category_hits;
            $category_stats[$cat_id]['size'] = $cat->category_size;
            $total_stats['files'] += $cat->category_files;
            $total_stats['hits'] += $cat->category_hits;
            $total_stats['size'] += $cat->category_size;
        }
    }
    // Calculate Paging
    $numposts = $total_stats['files'];
    $perpage = $file_sort['perpage'];
    $max_page = ceil($numposts / $perpage);
    if (empty($page) || $page == 0) {
        $page = 1;
    }
    $offset = ($page - 1) * $perpage;
    $pages_to_show = 10;
    $pages_to_show_minus_1 = $pages_to_show - 1;
    $half_page_start = floor($pages_to_show_minus_1 / 2);
    $half_page_end = ceil($pages_to_show_minus_1 / 2);
    $start_page = $page - $half_page_start;
    if ($start_page <= 0) {
        $start_page = 1;
    }
    $end_page = $page + $half_page_end;
    if ($end_page - $start_page != $pages_to_show_minus_1) {
        $end_page = $start_page + $pages_to_show_minus_1;
    }
    if ($end_page > $max_page) {
        $start_page = $max_page - $pages_to_show_minus_1;
        $end_page = $max_page;
    }
    if ($start_page <= 0) {
        $start_page = 1;
    }
    if ($offset + $perpage > $numposts) {
        $max_on_page = $numposts;
    } else {
        $max_on_page = $offset + $perpage;
    }
    if ($offset + 1 > $numposts) {
        $display_on_page = $numposts;
    } else {
        $display_on_page = $offset + 1;
    }
    // Get Sorting Group
    $group_sql = '';
    if ($file_sort['group'] == 1) {
        $group_sql = 'file_category ASC,';
    }
    // Get Files
    $files = $wpdb->get_results("SELECT * FROM {$wpdb->downloads} WHERE 1=1 {$category_sql} {$search_sql} AND file_permission != -2 ORDER BY {$group_sql} {$file_sort['by']} {$file_sort['order']} LIMIT {$offset}, {$file_sort['perpage']}");
    if ($files) {
        // Get Download Page Header
        $template_download_header = stripslashes(get_option('download_template_header'));
        if (get_option('download_nice_permalink') == '0' && preg_match('/[\\?\\&]page_id=(\\d+)/i', get_option('download_page_url'), $matches)) {
            $template_download_header = preg_replace('/(<form[^>]+>)/i', '$1<input type="hidden" name="page_id" value="' . $matches[1] . '" />', $template_download_header);
        }
        $template_download_header = str_replace("%TOTAL_FILES_COUNT%", number_format_i18n($total_stats['files']), $template_download_header);
        $template_download_header = str_replace("%TOTAL_HITS%", number_format_i18n($total_stats['hits']), $template_download_header);
        $template_download_header = str_replace("%TOTAL_SIZE%", format_filesize($total_stats['size']), $template_download_header);
        $template_download_header = str_replace("%TOTAL_SIZE_DEC%", format_filesize_dec($total_stats['size']), $template_download_header);
        $template_download_header = str_replace("%RECORD_START%", number_format_i18n($display_on_page), $template_download_header);
        $template_download_header = str_replace("%RECORD_END%", number_format_i18n($max_on_page), $template_download_header);
        $template_download_header = str_replace("%CATEGORY_ID%", $category, $template_download_header);
        $template_download_header = str_replace("%FILE_CATEGORY_NAME%", stripslashes($download_categories[$category]), $template_download_header);
        $template_download_header = str_replace("%FILE_SEARCH_WORD%", $search, $template_download_header);
        $template_download_header = str_replace("%DOWNLOAD_PAGE_URL%", get_option('download_page_url'), $template_download_header);
        $output = $template_download_header;
        // Loop Through Files
        $i = 1;
        $k = 1;
        $temp_cat_id = -1;
        $need_footer = 0;
        foreach ($files as $file) {
            $cat_id = intval($file->file_category);
            // Print Out Category Footer
            if ($need_footer && $temp_cat_id != $cat_id && $file_sort['group'] == 1) {
                // Get Download Category Footer
                $template_download_category_footer = stripslashes(get_option('download_template_category_footer'));
                $template_download_category_footer = str_replace("%FILE_CATEGORY_NAME%", stripslashes($download_categories[$cat_id]), $template_download_category_footer);
                $template_download_category_footer = str_replace("%CATEGORY_ID%", $cat_id, $template_download_category_footer);
                $template_download_category_footer = str_replace("%CATEGORY_URL%", download_category_url($cat_id), $template_download_category_footer);
                $template_download_category_footer = str_replace("%CATEGORY_FILES_COUNT%", number_format_i18n($category_stats[$cat_id]['files']), $template_download_category_footer);
                $template_download_category_footer = str_replace("%CATEGORY_HITS%", number_format_i18n($category_stats[$cat_id]['hits']), $template_download_category_footer);
                $template_download_category_footer = str_replace("%CATEGORY_SIZE%", format_filesize($category_stats[$cat_id]['size']), $template_download_category_footer);
                $template_download_category_footer = str_replace("%CATEGORY_SIZE_DEC%", format_filesize_dec($category_stats[$cat_id]['size']), $template_download_category_footer);
                $output .= $template_download_category_footer;
                $need_footer = 0;
            }
            // Print Out Category Header
            if ($temp_cat_id != $cat_id && $file_sort['group'] == 1) {
                // Get Download Category Header
                $template_download_category_header = stripslashes(get_option('download_template_category_header'));
                $template_download_category_header = str_replace("%FILE_CATEGORY_NAME%", stripslashes($download_categories[$cat_id]), $template_download_category_header);
                $template_download_category_header = str_replace("%CATEGORY_ID%", $cat_id, $template_download_category_header);
                $template_download_category_header = str_replace("%CATEGORY_URL%", download_category_url($cat_id), $template_download_category_header);
                $template_download_category_header = str_replace("%CATEGORY_FILES_COUNT%", number_format_i18n($category_stats[$cat_id]['files']), $template_download_category_header);
                $template_download_category_header = str_replace("%CATEGORY_HITS%", number_format_i18n($category_stats[$cat_id]['hits']), $template_download_category_header);
                $template_download_category_header = str_replace("%CATEGORY_SIZE%", format_filesize($category_stats[$cat_id]['size']), $template_download_category_header);
                $template_download_category_header = str_replace("%CATEGORY_SIZE_DEC%", format_filesize_dec($category_stats[$cat_id]['size']), $template_download_category_header);
                $output .= $template_download_category_header;
                $i = 1;
                $need_footer = 1;
            }
            // Get Download Listing
            $file_permission = intval($file->file_permission);
            $template_download_listing = get_option('download_template_listing');
            if ($file_permission > 0 && intval($current_user->wp_user_level) >= $file_permission && intval($user_ID) > 0 || $file_permission == 0 && intval($user_ID) > 0 || $file_permission == -1) {
                $template_download_listing = stripslashes($template_download_listing[0]);
            } else {
                $template_download_listing = stripslashes($template_download_listing[1]);
            }
            $template_download_listing = str_replace("%FILE_ID%", $file->file_id, $template_download_listing);
            $template_download_listing = str_replace("%FILE%", stripslashes($file->file), $template_download_listing);
            $template_download_listing = str_replace("%FILE_NAME%", download_search_highlight($search, stripslashes($file->file_name)), $template_download_listing);
            $template_download_listing = str_replace("%FILE_EXT%", file_extension(stripslashes($file->file)), $template_download_listing);
            $template_download_listing = str_replace("%FILE_ICON%", file_extension_image(stripslashes($file->file), $file_extensions_images), $template_download_listing);
            $template_download_listing = str_replace("%FILE_DESCRIPTION%", download_search_highlight($search, stripslashes($file->file_des)), $template_download_listing);
            $template_download_listing = str_replace("%FILE_SIZE%", format_filesize($file->file_size), $template_download_listing);
            $template_download_listing = str_replace("%FILE_SIZE_DEC%", format_filesize_dec($file->file_size), $template_download_listing);
            $template_download_listing = str_replace("%FILE_CATEGORY_ID%", $cat_id, $template_download_listing);
            $template_download_listing = str_replace("%FILE_CATEGORY_NAME%", stripslashes($download_categories[$cat_id]), $template_download_listing);
            $template_download_listing = str_replace("%FILE_DATE%", mysql2date(get_option('date_format'), gmdate('Y-m-d H:i:s', $file->file_date)), $template_download_listing);
            $template_download_listing = str_replace("%FILE_TIME%", mysql2date(get_option('time_format'), gmdate('Y-m-d H:i:s', $file->file_date)), $template_download_listing);
            $template_download_listing = str_replace("%FILE_UPDATED_DATE%", mysql2date(get_option('date_format'), gmdate('Y-m-d H:i:s', $file->file_updated_date)), $template_download_listing);
            $template_download_listing = str_replace("%FILE_UPDATED_TIME%", mysql2date(get_option('time_format'), gmdate('Y-m-d H:i:s', $file->file_updated_date)), $template_download_listing);
            $template_download_listing = str_replace("%FILE_HITS%", number_format_i18n($file->file_hits), $template_download_listing);
            $template_download_listing = str_replace("%FILE_DOWNLOAD_URL%", download_file_url($file->file_id, $file->file), $template_download_listing);
            $output .= $template_download_listing;
            // Assign Cat ID To Temp Cat ID
            $temp_cat_id = $cat_id;
            // Count Files
            $i++;
            $k++;
        }
        // Print Out Category Footer
        if ($need_footer) {
            // Get Download Category Footer
            $template_download_category_footer = stripslashes(get_option('download_template_category_footer'));
            $template_download_category_footer = str_replace("%FILE_CATEGORY_NAME%", stripslashes($download_categories[$cat_id]), $template_download_category_footer);
            $template_download_category_footer = str_replace("%CATEGORY_ID%", $cat_id, $template_download_category_footer);
            $template_download_category_footer = str_replace("%CATEGORY_URL%", download_category_url($cat_id), $template_download_category_footer);
            $template_download_category_footer = str_replace("%CATEGORY_FILES_COUNT%", number_format_i18n($category_stats[$cat_id]['files']), $template_download_category_footer);
            $template_download_category_footer = str_replace("%CATEGORY_HITS%", number_format_i18n($category_stats[$cat_id]['hits']), $template_download_category_footer);
            $template_download_category_footer = str_replace("%CATEGORY_SIZE%", format_filesize($category_stats[$cat_id]['size']), $template_download_category_footer);
            $template_download_category_footer = str_replace("%CATEGORY_SIZE_DEC%", format_filesize_dec($category_stats[$cat_id]['size']), $template_download_category_footer);
            $output .= $template_download_category_footer;
            $need_footer = 0;
        }
        // Get Download Page Footer
        $template_download_footer = stripslashes(get_option('download_template_footer'));
        if (get_option('download_nice_permalink') == '0' && preg_match('/[\\?\\&]page_id=(\\d+)/i', get_option('download_page_url'), $matches)) {
            $template_download_footer = preg_replace('/(<form[^>]+>)/i', '$1<input type="hidden" name="page_id" value="' . $matches[1] . '" />', $template_download_footer);
        }
        $template_download_footer = str_replace("%TOTAL_FILES_COUNT%", number_format_i18n($total_stats['files']), $template_download_footer);
        $template_download_footer = str_replace("%TOTAL_HITS%", number_format_i18n($total_stats['hits']), $template_download_footer);
        $template_download_footer = str_replace("%TOTAL_SIZE%", format_filesize($total_stats['size']), $template_download_footer);
        $template_download_footer = str_replace("%TOTAL_SIZE_DEC%", format_filesize_dec($total_stats['size']), $template_download_footer);
        $template_download_footer = str_replace("%CATEGORY_ID%", $category, $template_download_footer);
        $template_download_footer = str_replace("%FILE_CATEGORY_NAME%", stripslashes($download_categories[$category]), $template_download_footer);
        $template_download_footer = str_replace("%FILE_SEARCH_WORD%", $search, $template_download_footer);
        $template_download_footer = str_replace("%DOWNLOAD_PAGE_URL%", get_option('download_page_url'), $template_download_footer);
        $output .= $template_download_footer;
    } else {
        $template_download_none = stripslashes(get_option('download_template_none'));
        $output .= $template_download_none;
    }
    // Download Paging
    if ($max_page > 1) {
        $output .= stripslashes(get_option('download_template_pagingheader'));
        if (function_exists('wp_pagenavi')) {
            $output .= '<div class="wp-pagenavi">' . "\n";
        } else {
            $output .= '<div class="wp-downloadmanager-paging">' . "\n";
        }
        $output .= '<span class="pages">&#8201;' . sprintf(__('Page %s of %s', 'wp-downloadmanager'), number_format_i18n($page), number_format_i18n($max_page)) . '&#8201;</span>';
        if ($start_page >= 2 && $pages_to_show < $max_page) {
            $output .= '<a href="' . download_page_link(1) . '" title="' . __('&laquo; First', 'wp-downloadmanager') . '">&#8201;' . __('&laquo; First', 'wp-downloadmanager') . '&#8201;</a>';
            $output .= '<span class="extend">...</span>';
        }
        if ($page > 1) {
            $output .= '<a href="' . download_page_link($page - 1) . '" title="' . __('&laquo;', 'wp-downloadmanager') . '">&#8201;' . __('&laquo;', 'wp-downloadmanager') . '&#8201;</a>';
        }
        for ($i = $start_page; $i <= $end_page; $i++) {
            if ($i == $page) {
                $output .= '<span class="current">&#8201;' . number_format_i18n($i) . '&#8201;</span>';
            } else {
                $output .= '<a href="' . download_page_link($i) . '" title="' . number_format_i18n($i) . '">&#8201;' . number_format_i18n($i) . '&#8201;</a>';
            }
        }
        if (empty($page) || $page + 1 <= $max_page) {
            $output .= '<a href="' . download_page_link($page + 1) . '" title="' . __('&raquo;', 'wp-downloadmanager') . '">&#8201;' . __('&raquo;', 'wp-downloadmanager') . '&#8201;</a>';
        }
        if ($end_page < $max_page) {
            $output .= '<span class="extend">...</span>';
            $output .= '<a href="' . download_page_link($max_page) . '" title="' . __('Last &raquo;', 'wp-downloadmanager') . '">&#8201;' . __('Last &raquo;', 'wp-downloadmanager') . '&#8201;</a>';
        }
        $output .= '</div>';
        $output .= stripslashes(get_option('download_template_pagingfooter'));
    }
    return apply_filters('downloads_page', $output);
}