Guest User

wpdm-all-downloads

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