Advertisement
Guest User

wpdm-all-downloads.php

a guest
May 2nd, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 21.30 KB | None | 0 0
  1. <?php
  2. if (!defined('ABSPATH')) die();
  3. global $btnclass;
  4. if(!is_array($params)) $params = array();
  5. $p = serialize($params);
  6. $tid = md5($p);
  7. if(!isset($params['items_per_page'])) $params['items_per_page'] = 20;
  8. $cols = isset($params['cols'])?$params['cols']:'page_link,file_count,download_count|categories|update_date|download_link';
  9. $colheads = isset($params['colheads'])?$params['colheads']:'Title|Categories|Update Date|Download';
  10. $cols = explode("|", $cols);
  11. $colheads = explode("|", $colheads);
  12. foreach ($cols as $index => &$col){
  13.    $col = explode(",", $col);
  14.    $colheads[$index] = !isset($colheads[$index])?$col[0]:$colheads[$index];
  15. }
  16.  
  17. $column_positions = array();
  18.  
  19. //$coltemplate['title'] = $coltemplate['post_title'] = "%the_title%";
  20. $coltemplate['page_link'] = "<a class=\"package-title\" href=\"%s\">%s</a>";
  21.  
  22. if(isset($params['jstable']) && $params['jstable']==1):
  23.     $_cols =  explode("|", wpdm_valueof($params, 'cols', ['default' => '']));
  24.     $datatable_col = ( isset($params['order_by']) && $params['order_by'] == 'title' ) ? '0' : array_search(wpdm_valueof($params, 'order_by'), $_cols);
  25.     $datatable_order = ( isset($params['order']) && $params['order'] == 'DESC' ) ? 'desc' : 'asc';
  26.  
  27.     ?>
  28.     <script src="<?php echo WPDM_BASE_URL.'assets/js/jquery.dataTables.min.js' ?>"></script>
  29.     <script src="<?php echo WPDM_BASE_URL.'assets/js/dataTables.bootstrap4.min.js' ?>"></script>
  30.     <link href="<?php echo WPDM_BASE_URL.'assets/css/jquery.dataTables.min.css' ?>" rel="stylesheet" />
  31.  
  32.     <script>
  33.         jQuery(function($){
  34.  
  35.             var __dt = $('#wpdmmydls-<?php echo $tid; ?>').dataTable({
  36.                 "dom": '<"wpdmdt-toolbar"lfrB>t<"wpdmdt-toolbarb"ip>',
  37.                 responsive: true,
  38.                 "order": [[ <?php echo $datatable_col; ?>, "<?php echo $datatable_order; ?>" ]],
  39.                 "language": {
  40.                     "lengthMenu": "<?php _e("Display _MENU_ downloads per page",'download-manager')?>",
  41.                     "zeroRecords": "<?php _e("Nothing _START_ to - sorry",'download-manager')?>",
  42.                     "info": "<?php _e("Showing _START_ to _END_ of _TOTAL_ downloads",'download-manager')?>",
  43.                     "infoEmpty": "<?php _e("No downloads available",'download-manager')?>",
  44.                     "infoFiltered": "<?php _e("(filtered from _MAX_ total downloads)",'download-manager');?>",
  45.                     "emptyTable":     "<?php _e("No data available in table",'download-manager');?>",
  46.                     "infoPostFix":    "",
  47.                     "thousands":      ",",
  48.                     "loadingRecords": "<?php _e("Loading...",'download-manager'); ?>",
  49.                     "processing":     "<?php _e("Processing...",'download-manager'); ?>",
  50.                     "search":         "<?php _e("Search:",'download-manager'); ?>",
  51.                     "paginate": {
  52.                         "first":      "<?php _e("First",'download-manager'); ?>",
  53.                         "last":       "<?php _e("Last",'download-manager'); ?>",
  54.                         "next":       "<?php _e("Next",'download-manager'); ?>",
  55.                         "previous":   "<?php _e("Previous",'download-manager'); ?>"
  56.                     },
  57.                     "aria": {
  58.                         "sortAscending":  " : <?php _e("activate to sort column ascending",'download-manager'); ?>",
  59.                         "sortDescending": ": <?php _e("activate to sort column descending",'download-manager'); ?>"
  60.                     }
  61.                 },
  62.                 "iDisplayLength": <?php echo $params['items_per_page'] ?>,
  63.                 "aLengthMenu": [[<?php echo $params['items_per_page']; ?>, 10, 25, 50, -1], [<?php echo $params['items_per_page']; ?>, 10, 25, 50, "<?php _e("All",'download-manager'); ?>"]]
  64.             });
  65.  
  66.             <?php if(count($_GET) > 0){ ?>
  67.             $("div.wpdmdt-toolbar .dataTables_filter").append('<a href="<?php the_permalink(); ?>" class="btn btn-secondary ml-3" style="margin-top: -5px;border: 0;">Reset Filter</a>');
  68.             <?php } ?>
  69.         });
  70.     </script>
  71. <?php endif; ?>
  72. <style>
  73.     .wpdmdt-toolbar {
  74.         padding: 10px 10px 0 10px;
  75.     }
  76.     .wpdmdt-toolbarb {
  77.         padding: 5px 10px 10px;
  78.     }
  79.     .wpdmdt-toolbar > div {
  80.         display: inline-block;
  81.     }
  82.     table,td,th{
  83.         border: 0;
  84.     }
  85.     #wpdm-all-packages .card{
  86.         overflow: hidden;
  87.     }
  88.     .dataTables_wrapper .table{
  89.         margin: 0;
  90.     }
  91.     #wpdmmydls-<?php echo $tid; ?>{
  92.         border-bottom: 1px solid #dddddd;
  93.         border-top: 1px solid #dddddd;
  94.         font-size: 10pt;
  95.         min-width: 100%;
  96.     }
  97.     #wpdmmydls-<?php echo $tid; ?> .wpdm-download-link img{
  98.         box-shadow: none !important;
  99.         max-width: 100%;
  100.     }
  101.     .w3eden .pagination{
  102.         margin: 0 !important;
  103.     }
  104.     #wpdmmydls-<?php echo $tid; ?> td:not(:first-child){
  105.         vertical-align: middle !important;
  106.     }
  107.     #wpdmmydls-<?php echo $tid; ?> td.__dt_col_download_link .btn{
  108.         display: block;
  109.         width: 100%;
  110.     }
  111.     #wpdmmydls-<?php echo $tid; ?> td.__dt_col_download_link,
  112.     #wpdmmydls-<?php echo $tid; ?> th#download_link{
  113.         max-width: 155px !important;
  114.         width: 155px;
  115.  
  116.     }
  117.     #wpdmmydls-<?php echo $tid; ?> th{
  118.         background-color: rgba(0,0,0,0.04);
  119.         border-bottom: 1px solid rgba(0,0,0,0.025);
  120.     }
  121.     #wpdmmydls-<?php echo $tid; ?>_length label,
  122.     #wpdmmydls-<?php echo $tid; ?>_filter label{
  123.         font-weight: 400;
  124.     }
  125.     #wpdmmydls-<?php echo $tid; ?>_filter input[type=search]{
  126.         display: inline-block;
  127.         width: 200px;
  128.     }
  129.     #wpdmmydls-<?php echo $tid; ?>_length select{
  130.         display: inline-block;
  131.         width: 60px;
  132.     }
  133.  
  134.     #wpdmmydls-<?php echo $tid; ?> .package-title{
  135.         color:#36597C;
  136.         font-size: 11pt;
  137.         font-weight: 700;
  138.     }
  139.     #wpdmmydls-<?php echo $tid; ?> .small-txt{
  140.         margin-right: 7px;
  141.     }
  142.     #wpdmmydls-<?php echo $tid; ?> td{
  143.         min-width: 150px;
  144.     }
  145.  
  146.     #wpdmmydls-<?php echo $tid; ?> td.__dt_col_categories{
  147.         max-width: 300px;
  148.     }
  149.  
  150.     #wpdmmydls-<?php echo $tid; ?> .small-txt,
  151.     #wpdmmydls-<?php echo $tid; ?> small{
  152.         font-size: 9pt;
  153.     }
  154.     .w3eden .table-striped tbody tr:nth-of-type(2n+1) {
  155.         background-color: rgba(0,0,0,0.015);
  156.     }
  157.     .dataTables_wrapper .dataTables_paginate .paginate_button:active,
  158.     .dataTables_wrapper .dataTables_paginate .paginate_button:focus,
  159.     .dataTables_wrapper .dataTables_paginate .paginate_button:hover,
  160.     .dataTables_wrapper .dataTables_paginate .paginate_button{
  161.         margin: 0 !important;
  162.         padding: 0 !important;
  163.         border: 0 !important;
  164.         background: transparent !important;
  165.     }
  166.  
  167.  
  168.     @media (max-width: 799px) {
  169.         #wpdmmydls-<?php echo $tid; ?> tr {
  170.             display: block;
  171.             border: 3px solid rgba(0,0,0,0.3) !important;
  172.             margin-bottom: 10px !important;
  173.             position: relative;
  174.         }
  175.         #wpdmmydls-<?php echo $tid; ?> thead{
  176.             display: none;
  177.         }
  178.         #wpdmmydls-<?php echo $tid; ?>,
  179.         #wpdmmydls-<?php echo $tid; ?> td:first-child {
  180.             border: 0 !important;
  181.         }
  182.         #wpdmmydls-<?php echo $tid; ?> td {
  183.             display: block;
  184.         }
  185.         #wpdmmydls-<?php echo $tid; ?> td.__dt_col_download_link {
  186.             display: block;
  187.             max-width: 100% !important;
  188.             width: auto !important;
  189.  
  190.         }
  191.     }
  192.  
  193.  
  194. </style>
  195. <div class="w3eden">
  196.     <div id="wpdm-all-packages">
  197.         <table id="wpdmmydls-<?php echo $tid; ?>" class="table table-striped wpdm-all-packages-table">
  198.             <thead>
  199.             <tr>
  200.                 <?php foreach ($colheads as $ix => $colhead){
  201.                     $_colhead = explode("::", $colhead);
  202.                     $width = (isset($_colhead[1]))?"width: {$_colhead[1]} !important;max-width: {$_colhead[1]} !important;":"";
  203.                     ?>
  204.                 <th style="<?php echo $width; ?>"  id="<?php echo $cols[$ix][0]; ?>" class="<?php if($ix > 0) echo 'hidden-sm hidden-xs'; ?>"><?php _e($_colhead[0],'download-manager'); ?></th>
  205.                 <?php } ?>
  206.  
  207.             </tr>
  208.             </thead>
  209.             <tbody>
  210.             <?php
  211.  
  212.  
  213.             $cfurl = get_permalink();
  214.  
  215.             $query_params = array("post_type"=>"wpdmpro","posts_per_page"=>$items,"offset"=>$offset);
  216.             if(isset($tax_query)) $query_params['tax_query'] = $tax_query;
  217.             $query_params['orderby'] = (isset($params['order_by']))?$params['order_by']:'date';
  218.  
  219.             $order_field = isset($params['order_by']) ? $params['order_by'] : 'date';
  220.             $order = isset($params['order']) ? $params['order'] : 'DESC';
  221.  
  222.             $order_fields = array('__wpdm_download_count','__wpdm_view_count','__wpdm_package_size_b');
  223.             if(!in_array( "__wpdm_".$order_field, $order_fields)) {
  224.                 $query_params['orderby'] = $order_field;
  225.                 $query_params['order'] = $order;
  226.             } else {
  227.                 $query_params['orderby'] = 'meta_value_num';
  228.                 $query_params['meta_key'] = "__wpdm_".$order_field;
  229.                 $query_params['order'] = $order;
  230.             }
  231.  
  232.             if(is_array(wpdm_query_var('tax'))){
  233.                 foreach (wpdm_query_var('tax') as $tax => $term) {
  234.                     $query_params['tax_query'][] = [
  235.                             'taxonomy' => $tax,
  236.                         'field' => 'slug',
  237.                         'terms' => [$term]
  238.                     ];
  239.                     $query_params['tax_query']['relation'] = 'AND';
  240.                 }
  241.             }
  242.  
  243.             $taxonomies = get_object_taxonomies( 'wpdmpro' );
  244.  
  245.             $q = new WP_Query($query_params);
  246.             $total_files = $q->found_posts;
  247.             while ($q->have_posts()): $q->the_post();
  248.  
  249.                 $ext = "unknown";
  250.                 $data = wpdm_custom_data(get_the_ID());
  251.  
  252.                 global $post;
  253.                 $data += (array)$post;
  254.                 $data['id'] = $data['ID'];
  255.  
  256.                 if(isset($data['files'])&&count($data['files'])){
  257.                     if(count($data['files']) == 1) {
  258.                         $tmpavar = $data['files'];
  259.                         $ffile = $tmpvar = array_shift($tmpavar);
  260.                         $tmpvar = explode(".", $tmpvar);
  261.                         $ext = count($tmpvar) > 1 ? end($tmpvar) : $ext;
  262.                     } else
  263.                         $ext = 'zip';
  264.                 } else $data['files'] = array();
  265.  
  266.                 foreach ($taxonomies as $taxonomy) {
  267.                     $terms = wp_get_post_terms(get_the_ID(), $taxonomy);
  268.                     $_terms = array();
  269.                     foreach ($terms as $term) {
  270.                         $lurl = add_query_arg(['tax' => [$taxonomy => $term->slug]], $cfurl);
  271.                         $_terms[] = "<a class='sbyc' href='{$lurl}'>{$term->name}</a>";
  272.                     }
  273.                     $_terms = @implode(", ", $_terms);
  274.                     $data[$taxonomy] = $_terms;
  275.                 }
  276.  
  277.                 /*$tags = wp_get_post_terms(get_the_ID(), 'wpdmtag');
  278.                 $ftags = array();
  279.                 foreach($tags as $tag){
  280.                     $lurl = add_query_arg(['wpdmt' => $tag->slug], $cfurl);
  281.                     $ftags[] = "<a class='sbyc' href='{$lurl}'>{$tag->name}</a>";
  282.                 }
  283.                 $tags = @implode(", ", $ftags);*/
  284.  
  285.                 if($ext=='') $ext = 'unknown';
  286.  
  287.                 $ext = \WPDM\libs\FileSystem::fileTypeIcon($ext);
  288.  
  289.                 if(isset($data['icon']) && $data['icon'] !== '') $ext = $data['icon'];
  290.  
  291.                 if(isset($params['thumb']) && (int)$params['thumb'] == 1) $ext = wpdm_thumb($post, array(96,104), 'url');
  292.  
  293.                 $data['download_url'] = '';
  294.                 $data['download_link'] = \WPDM\Package::downloadLink($data['ID'], 0, array('template_type' => 'link'));
  295.                 $data = apply_filters("wpdm_after_prepare_package_data", $data);
  296.                 $download_link = htmlspecialchars_decode($data['download_link']);
  297.                 $page_link = "<a class=\"package-title\" href='".get_the_permalink(get_the_ID())."'>".__( 'Download', 'download-manager' )."</a><br/>";
  298.                 if(((isset($data['base_price']) && $data['base_price'] > 0) || (isset($data['pay_as_you_want']) && (int)$data['pay_as_you_want'] === 1)) && function_exists('wpdmpp_currency_sign'))
  299.                     $download_link = wpdmpp_waytocart($data, 'btn-primary');
  300.                         //"<a href='#buy' data-package='{$data['ID']}' class='btn btn-sm1 btn-info wpdm-download-link wpdm-download-locked'>".__( "Buy" , "download-manager" )." ( ".$data['currency'].$data['effective_price']." )</a>";
  301.                 if(\WPDM\Package::userCanAccess($data['ID']) || !get_option("_wpdm_hide_all", 0)){
  302.                     ?>
  303.  
  304.                     <tr class="__dt_row">
  305.                         <?php
  306.                         $tcols = $cols;
  307.                         array_shift($tcols);
  308.                         foreach ($cols as $colx => $cold){
  309.                             $dor = array('publish_date' => strtotime(get_the_date('Y-m-d')), 'create_date' => strtotime(get_the_date('Y-m-d')), 'update_date' => strtotime(get_the_modified_date('Y-m-d', get_the_ID())));
  310.                             ?>
  311.                         <td <?php if(in_array($cold[0], array('publish_date', 'update_date','create_date'))) { ?> data-order="<?php echo $dor[$cold[0]]; ?>" <?php } ?> class="__dt_col_<?php echo $colx; ?> __dt_col __dt_col_<?php echo $cold[0]; ?>" <?php if($colx == 0) { ?>style="background-image: url('<?php echo $ext ; ?>');background-size: 36px;background-position: 5px 8px;background-repeat:  no-repeat;padding-left: 52px;line-height: normal;"<?php } ?>>
  312.                             <?php
  313.  
  314.                             foreach ($cold as $cx => $c){
  315.                                 $cxc = ($cx > 0)?'small-txt':'';
  316.                                 switch ($c) {
  317.                                     case 'title':
  318.                                         echo "<strong>".get_the_title()."</strong><br/>";
  319.                                         break;
  320.                                     case 'page_link':
  321.                                         echo "<a class=\"package-title\" href='".get_the_permalink(get_the_ID())."'>".__( "Download", "download-manager" )."</a><br/>";
  322.                                         break;
  323.                                     case 'excerpt':
  324.                                     case (preg_match('/excerpt_.+/', $c) ? true : false) :
  325.                                         $xcol = explode("_", $c);
  326.                                         $len = isset($xcol[1])?$xcol[1]:false;
  327.                                         $cont = strip_tags($data['post_content']);
  328.  
  329.                                         if(!$len)
  330.                                             echo "<div class='__dt_excerpt {$cxc}'>".get_the_excerpt()."</div>";
  331.                                         else {
  332.                                             $excerpt = strlen($cont) > $len?substr($cont, 0, strpos($cont, ' ', $len)):$cont;
  333.                                             echo "<div class='__dt_excerpt {$cxc}'>" . $excerpt . "</div>";
  334.                                         }
  335.                                         break;
  336.                                     case 'file_count':
  337.                                         if($cx > 0)
  338.                                             echo "<span class='__dt_file_count {$cxc}'><i class=\"far fa-copy\"></i> ". count($data['files'])." " . __('file(s)','download-manager')."</span>";
  339.                                         else
  340.                                             echo "<span class=\"hidden-md hidden-lg td-mobile\">{$colheads[$colx]}: </span><span class='__dt_file_count {$cxc}'>".count($data['files'])."</span>";
  341.                                         break;
  342.                                     case 'download_count':
  343.                                         if($cx > 0)
  344.                                             echo "<span class='__dt_download_count {$cxc}'><i class=\"far fa-arrow-alt-circle-down\"></i> ". (isset($data['download_count'])?$data['download_count']:0)." ".(isset($data['download_count']) && $data['download_count'] > 1 ?  __('downloads','download-manager') : __('download','download-manager'))."</span>";
  345.                                         else
  346.                                             echo "<span class=\"hidden-md hidden-lg td-mobile\">{$colheads[$colx]}: </span><span class='__dt_download_count {$cxc}'>{$data['download_count']}</span>";
  347.                                         break;
  348.                                     case 'view_count':
  349.                                         if($cx > 0)
  350.                                             echo "<span class='__dt_view_count {$cxc}'><i class=\"fa fa-eye\"></i> ". (isset($data['view_count'])?$data['view_count']:0)." ".(isset($data['view_count']) && $data['view_count'] > 1 ?  __('views','download-manager') : __('view','download-manager'))."</span>";
  351.                                         else
  352.                                             echo "<span class=\"hidden-md hidden-lg td-mobile\">{$colheads[$colx]}: </span><span class='__dt_view_count'>{$data['view_count']}</span>";
  353.                                         break;
  354.                                     case 'categories':
  355.                                         echo "<span class='__dt_categories {$cxc}'>".$data['wpdmcategory']."</span>";
  356.                                         break;
  357.                                     case 'tags':
  358.                                         echo "<span class='__dt_categories {$cxc}'>".$data['wpdmtag']."</span>";
  359.                                         break;
  360.                                     case 'update_date':
  361.                                         echo "<span class='__dt_update_date {$cxc}'>".get_the_modified_date('', get_the_ID())."</span>";
  362.                                         break;
  363.                                     case 'publish_date':
  364.                                         echo "<span class='__dt_publish_date {$cxc}'>".get_the_date()."</span>";
  365.                                         break;
  366.                                     case 'download_link':
  367.                                         echo $page_link ? $page_link : '<button type="button" disabled="disabled" class="btn btn-danger btn-block">'.__( "Download", "download-manager" ).'</button>';
  368.                                         break;
  369.                                     case 'audio_player':
  370.                                         $data['files'] = \WPDM\Package::getFiles($data['ID']);
  371.                                         echo \WPDM\Package::audioPlayer($data, true, 'success');
  372.                                         break;
  373.                                     default:
  374.                                         if(isset($data[$c])) {
  375.                                             if ($cx > 0)
  376.                                                 echo "<span class='__dt_{$c} {$cxc}'>" . $data[$c] . "</span>";
  377.                                             else
  378.                                                 echo $data[$c];
  379.                                         }
  380.                                         break;
  381.  
  382.  
  383.                             }}
  384.                             if($colx == 0) echo '<div class="hidden-md hidden-lg td-mobile"></div>';
  385.                                         ?>
  386.  
  387.  
  388.                         </td>
  389.                         <?php }  ?>
  390.  
  391.                     </tr>
  392.                 <?php } endwhile; ?>
  393.             <?php if((!isset($params['jstable']) || $params['jstable']==0) && $total_files==0): ?>
  394.                 <tr>
  395.                     <td colspan="4" class="text-center">
  396.  
  397.                         <?php echo isset($params['no_data_msg']) && $params['no_data_msg']!=''?$params['no_data_msg']:__('No Packages Found','download-manager'); ?>
  398.  
  399.                     </td>
  400.                 </tr>
  401.             <?php endif; ?>
  402.             </tbody>
  403.         </table>
  404.  
  405.         <?php
  406.         global $wp_rewrite,$wp_query;
  407.  
  408.         isset($wp_query->query_vars['paged']) && $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
  409.  
  410.         $pagination = array(
  411.             'base' => @add_query_arg('paged','%#%'),
  412.             'format' => '',
  413.             'total' => ceil($total_files/$items),
  414.             'current' => $cp,
  415.             'show_all' => false,
  416.             'type' => 'list',
  417.             'prev_next'    => True,
  418.             'prev_text' => '<i class="fa fa-long-arrow-left"></i> '.__('Previous', 'download-manager'),
  419.             'next_text' => __('Next', 'download-manager').' <i class="fa fa-long-arrow-right"></i>',
  420.         );
  421.  
  422.         if( $wp_rewrite->using_permalinks() )
  423.             $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');
  424.  
  425.         if( !empty($wp_query->query_vars['s']) )
  426.             $pagination['add_args'] = array('s'=>get_query_var('s'));
  427.  
  428.         echo  "<div class='text-center'>".str_replace("<ul class='page-numbers'>","<ul class='page-numbers pagination pagination-centered'>",paginate_links($pagination))."</div>";
  429.  
  430.         wp_reset_query();
  431.         ?>
  432.  
  433.     </div>
  434. </div>
  435.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement