Advertisement
Guest User

all-packages-shortcode.php

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