<?php

if (!defined('ABSPATH')) {
    die('Error!');
}
do_action("wpdm_onstart_download", $package);
global $current_user, $dfiles;
$speed = 1024;
//in KB - default 1 MB
$speed = apply_filters('wpdm_download_speed', $speed);
get_currentuserinfo();
if (wpdm_is_download_limit_exceed($package['ID'])) {
    wp_die(__msg('DOWNLOAD_LIMIT_EXCEED'));
}
$files = $package['files'];
$dir = isset($package['package_dir']) ? $package['package_dir'] : '';
if ($dir != '') {
    $dfiles = array();
    $dfiles = wpdm_get_files($dir);
}
$log = new Stats();
$oid = isset($_GET['oid']) ? esc_attr($_GET['oid']) : '';
$indsc = 1;
$indsc = isset($_GET['ind']) && get_option('__wpdm_ind_stats') == 0 ? 0 : 1;
if ($indsc && !isset($_GET['nostat'])) {
    $log->NewStat($package['ID'], $current_user->ID, $oid);
}
if (count($files) == 0 && count($dfiles) == 0) {
    if (isset($package['sourceurl']) && $package['sourceurl'] != '') {
        if (!isset($package['url_protect']) || $package['url_protect'] == 0 && strpos($package['sourceurl'], '://')) {
            header('location: ' . $package['sourceurl']);
 /**
  * @usage Generate download link of a package
  * @param $package
  * @param int $embed
  * @param array $extras
  * @return string
  */
 function prepareDownloadLink(&$package, $embed = 0, $extras = array())
 {
     global $wpdb, $current_user, $wpdm_download_icon, $wpdm_download_lock_icon, $btnclass;
     if (is_array($extras)) {
         extract($extras);
     }
     $data = '';
     get_currentuserinfo();
     $package['link_url'] = home_url('/?download=1&');
     $package['link_label'] = !isset($package['link_label']) || $package['link_label'] == '' ? __("Download", "wpdmpro") : $package['link_label'];
     //Change link label using a button image
     $package['link_label'] = apply_filters('wpdm_button_image', $package['link_label'], $package);
     $package['download_url'] = wpdm_download_url($package);
     if (wpdm_is_download_limit_exceed($package['ID'])) {
         $package['download_url'] = '#';
         $package['link_label'] = __('Download Limit Exceeded', 'wpdmpro');
     }
     if (isset($package['expire_date']) && $package['expire_date'] != "" && strtotime($package['expire_date']) < time()) {
         $package['download_url'] = '#';
         $package['link_label'] = __('Download was expired on', 'wpdmpro') . " " . date_i18n(get_option('date_format') . " h:i A", strtotime($package['expire_date']));
         $package['download_link'] = "<a href='#'>{$package['link_label']}</a>";
         return "<div class='alert alert-warning'><b>" . __('Download:', 'wpdmpro') . "</b><br/>{$package['link_label']}</div>";
     }
     if (isset($package['publish_date']) && $package['publish_date'] != '' && strtotime($package['publish_date']) > time()) {
         $package['download_url'] = '#';
         $package['link_label'] = __('Download will be available from ', 'wpdmpro') . " " . date_i18n(get_option('date_format') . " h:i A", strtotime($package['publish_date']));
         $package['download_link'] = "<a href='#'>{$package['link_label']}</a>";
         return "<div class='alert alert-warning'><b>" . __('Download:', 'wpdmpro') . "</b><br/>{$package['link_label']}</div>";
     }
     $link_label = isset($package['link_label']) ? $package['link_label'] : __('Download', 'wpdmpro');
     $package['access'] = wpdm_allowed_roles($package['ID']);
     if ($package['download_url'] != '#') {
         $package['download_link'] = "<a class='wpdm-download-link wpdm-download-locked {$btnclass}' rel='nofollow' href='#' onclick=\"location.href='{$package['download_url']}';return false;\"><i class='{$wpdm_download_icon}'></i>{$link_label}</a>";
     } else {
         $package['download_link'] = "<div class='alert alert-warning'><b>" . __('Download:', 'wpdmpro') . "</b><br/>{$link_label}</div>";
     }
     $caps = array_keys($current_user->caps);
     $role = array_shift($caps);
     $matched = is_array(@maybe_unserialize($package['access'])) && is_user_logged_in() ? array_intersect($current_user->roles, @maybe_unserialize($package['access'])) : array();
     $skiplink = 0;
     if (is_user_logged_in() && count($matched) <= 0 && !@in_array('guest', @maybe_unserialize($package['access']))) {
         $package['download_url'] = "#";
         $package['download_link'] = $package['download_link_extended'] = stripslashes(get_option('wpdm_permission_msg'));
         $package = apply_filters('download_link', $package);
         if (get_option('_wpdm_hide_all', 0) == 1) {
             $package['download_link'] = $package['download_link_extended'] = 'blocked';
         }
         return $package['download_link'];
     }
     if (!@in_array('guest', @maybe_unserialize($package['access'])) && !is_user_logged_in()) {
         $loginform = wpdm_login_form(array('redirect' => get_permalink($package['ID'])));
         if (get_option('_wpdm_hide_all', 0) == 1) {
             return 'loginform';
         }
         $package['download_url'] = home_url('/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
         $package['download_link'] = stripcslashes(str_replace(array("[loginform]", "[this_url]"), array($loginform, get_permalink($package['ID'])), get_option('wpdm_login_msg')));
         return get_option('__wpdm_login_form', 0) == 1 ? $loginform : $package['download_link'];
     }
     $package = apply_filters('download_link', $package);
     $unqid = uniqid();
     if (!isset($package['quota']) || isset($package['quota']) && $package['quota'] > 0 && $package['quota'] > $package['download_count'] || $package['quota'] == 0) {
         $lock = 0;
         //isset($package['password_lock']) && (int)$package['password_lock'] == 1 &&
         if ($package['password'] != '') {
             $lock = 'locked';
             $data = \WPDM\PackageLocks::AskPassword($package);
         }
         $sociallock = "";
         if (isset($package['captcha_lock']) && (int) $package['captcha_lock'] == 1) {
             $lock = 'locked';
             $sociallock .= \WPDM\PackageLocks::reCaptchaLock($package, true);
         }
         $extralocks = '';
         $extralocks = apply_filters("wpdm_download_lock", $extralocks, $package);
         if (is_array($extralocks) && $extralocks['lock'] === 'locked') {
             if (isset($extralocks['type']) && $extralocks['type'] == 'social') {
                 $sociallock .= $extralocks['html'];
             } else {
                 $data .= $extralocks['html'];
             }
             $lock = 'locked';
         }
         if ($sociallock != "") {
             $data .= "<div class='panel panel-default'><div class='panel-heading'>" . __("Download", "wpdmpro") . "</div><div class='panel-body wpdm-social-locks text-center'>{$sociallock}</div></div>";
         }
         if ($lock === 'locked') {
             $popstyle = isset($popstyle) && in_array($popstyle, array('popup', 'pop-over')) ? $popstyle : 'pop-over';
             if ($embed == 1) {
                 $adata = "</strong><table class='table all-locks-table' style='border:0px'><tr><td style='padding:5px 0px;border:0px;'>" . $data . "</td></tr></table>";
             } else {
                 $dataattrs = $popstyle == 'pop-over' ? 'data-title="<button type=button id=\'close\' class=\'btn btn-link btn-xs pull-right po-close\' style=\'margin-top:-4px;margin-right:-10px\'><i class=\'fa fa-times text-danger\'></i></button> ' . __('Download', 'wpdmpro') . ' ' . $package['title'] . '"' : 'data-toggle="modal" data-target="#pkg_' . $package['ID'] . "_" . $unqid . '"';
                 $adata = '<a href="#pkg_' . $package['ID'] . "_" . $unqid . '" ' . $dataattrs . ' class="wpdm-download-link wpdm-download-locked ' . $popstyle . ' ' . $btnclass . '"><i class=\'' . $wpdm_download_lock_icon . '\'></i>' . $package['link_label'] . '</a>';
                 if ($popstyle == 'pop-over') {
                     $adata .= '<div class="modal fade"><div class="row all-locks"  id="pkg_' . $package['ID'] . "_" . $unqid . '">' . $data . '</div></div>';
                 } else {
                     $adata .= '<div class="modal fade" role="modal" id="pkg_' . $package['ID'] . "_" . $unqid . '"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><strong style="margin:0px;font-size:12pt">' . __('Download') . '</strong></div><div class="modal-body">' . $data . '</div><div class="modal-footer text-right"><button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Close</button></div></div></div></div>';
                 }
             }
             $data = $adata;
         }
         if ($lock !== 'locked') {
             $data = $package['download_link'];
         }
     } else {
         $data = __("Download limit exceeded!", 'wpdmpro');
     }
     //return str_replace(array("\r","\n"),"",$data);
     return $data;
 }
Example #3
0
function wpdm_package_file_list($file)
{
    global $current_user;
    $file['files'] = maybe_unserialize($file['files']);
    $fhtml = '';
    $idvdl = isset($file['individual_file_download']) ? $file['individual_file_download'] : 0;
    $pd = isset($file['publish_date']) && $file['publish_date'] != "" ? strtotime($file['publish_date']) : 0;
    $xd = isset($file['expire_date']) && $file['expire_date'] != "" ? strtotime($file['expire_date']) : 0;
    $cur = is_user_logged_in() ? $current_user->roles : array('guest');
    if ($xd > 0 && $xd < time() || $pd > 0 && $pd > time()) {
        $idvdl = 0;
    }
    if (count($file['files']) > 0) {
        $fileinfo = isset($file['fileinfo']) ? $file['fileinfo'] : array();
        $pwdlock = isset($file['password_lock']) ? $file['password_lock'] : 0;
        //Check if any other lock option apllied for this package
        $olock = wpdm_is_locked($file['ID']) ? 1 : 0;
        $swl = 0;
        if (!isset($file['quota']) || $file['quota'] <= 0) {
            $file['quota'] = 9999999999999;
        }
        if (is_user_logged_in()) {
            $cur[] = 'guest';
        }
        if (!isset($file['access']) || count($file['access']) == 0 || !array_intersect($file['access'], $cur) || wpdm_is_download_limit_exceed($file['ID']) || $file['quota'] <= $file['download_count']) {
            $olock = 1;
        }
        $pwdcol = $dlcol = '';
        if ($pwdlock && $idvdl) {
            $pwdcol = "<th>" . __("Password", "wpdmpro") . "</th>";
        }
        if ($idvdl && ($pwdlock || !$olock)) {
            $dlcol = "<th align=center>" . __("Download", "wpdmpro") . "</th>";
            $swl = 1;
        }
        $allfiles = is_array($file['files']) ? $file['files'] : array();
        $dir = isset($file['package_dir']) ? $file['package_dir'] : '';
        $dfiles = array();
        if ($dir != '') {
            $dfiles = wpdm_get_files($dir);
        }
        //$allfiles = array_merge($allfiles, $dfiles);
        $fhtml = "<table class='wpdm-filelist table table-hover'><tr><th>" . __("File", "wpdmpro") . "</th>{$pwdcol}{$dlcol}</tr>";
        if (is_array($allfiles)) {
            foreach ($allfiles as $ind => $sfile) {
                if (!@is_array($fileinfo[$sfile])) {
                    $fileinfo[$sfile] = array();
                }
                if (!isset($fileinfo[$sfile]['password'])) {
                    $fileinfo[$sfile]['password'] = "";
                }
                if ($swl) {
                    if ($fileinfo[$sfile]['password'] == '' && $pwdlock) {
                        $fileinfo[$sfile]['password'] = $file['password'];
                    }
                    $ttl = isset($fileinfo[$sfile]['title']) && $fileinfo[$sfile]['title'] != "" ? $fileinfo[$sfile]['title'] : preg_replace("/([0-9]+)_/", "", basename($sfile));
                    $fhtml .= "<tr><td>{$ttl}</td>";
                    $fileinfo[$sfile]['password'] = $fileinfo[$sfile]['password'] == '' ? $file['password'] : $fileinfo[$sfile]['password'];
                    if ($fileinfo[$sfile]['password'] != '' && $pwdlock) {
                        $fhtml .= "<td width='110' align=right><input  onkeypress='jQuery(this).removeClass(\"input-error\");' size=10 type='password' value='' id='pass_{$file['ID']}_{$ind}' placeholder='Password' name='pass' class='form-control input-sm inddlps' /></td>";
                    }
                    if ($fileinfo[$sfile]['password'] != '' && $pwdlock) {
                        $fhtml .= "<td width=150><button class='inddl btn btn-primary btn-sm' file='{$sfile}' rel='" . wpdm_download_url($file) . "&ind=" . $ind . "' pass='******'ID']}_{$ind}'><i class='fa fa-download'></i>&nbsp;" . __("Download", "wpdmpro") . "</button></td></tr>";
                    } else {
                        $fhtml .= "<td width=150 align=center><a class='btn btn-primary btn-xs' href='" . wpdm_download_url($file) . "&ind=" . $ind . "'><i style='opacity:0.5;margin-top:0px' class='fa fa-download'></i>&nbsp;" . __("Download", "wpdmpro") . "</a></td></tr>";
                    }
                } else {
                    $ttl = !isset($fileinfo[$sfile]['title']) || $fileinfo[$sfile]['title'] == '' ? preg_replace("/([0-9]+)wpdm_/", "", basename($sfile)) : $fileinfo[$sfile]['title'];
                    $fhtml .= "<tr><td>{$ttl}</td></tr>";
                }
            }
        }
        if (is_array($dfiles)) {
            foreach ($dfiles as $ind => $sfile) {
                if (!@is_array($fileinfo[$sfile])) {
                    $fileinfo[$sfile] = array();
                }
                if (!isset($fileinfo[$sfile]['password'])) {
                    $fileinfo[$sfile]['password'] = "";
                }
                if ($idvdl == 1 && ($pwdlock || !$olock)) {
                    if ($fileinfo[$sfile]['password'] == '' && $pwdlock) {
                        $fileinfo[$sfile]['password'] = $file['password'];
                    }
                    $ttl = isset($fileinfo[$sfile]['title']) && $fileinfo[$sfile]['title'] != "" ? $fileinfo[$sfile]['title'] : str_replace('/', " <i class='fa fa-angle-right text-primary'></i> ", str_replace($dir, "", $sfile));
                    $fhtml .= "<tr><td>{$ttl}</td>";
                    $fileinfo[$sfile]['password'] = $fileinfo[$sfile]['password'] == '' ? $file['password'] : $fileinfo[$sfile]['password'];
                    if ($fileinfo[$sfile]['password'] != '' && $pwdlock) {
                        $fhtml .= "<td width='110' align=right><input  onkeypress='jQuery(this).removeClass(\"input-error\");' size=10 type='password' value='' id='pass_{$file['ID']}_{$ind}' placeholder='Password' name='pass' class='form-control input-sm inddlps' /></td>";
                    }
                    if ($fileinfo[$sfile]['password'] != '' && $pwdlock) {
                        $fhtml .= "<td width=150><button class='inddl btn btn-primary btn-sm' file='{$sfile}' rel='" . wpdm_download_url($file) . "&ind=" . (count($allfiles) + $ind) . "' pass='******'ID']}_{$ind}'><i class='fa fa-download'></i>&nbsp;Download</button></td></tr>";
                    } else {
                        $fhtml .= "<td width=150 align=center><a class='btn btn-primary btn-xs' href='" . wpdm_download_url($file) . "&ind=" . $ind . "'><i style='opacity:0.5;margin-top:0px' class='fa fa-download-alt'></i>&nbsp;Download</a></td></tr>";
                    }
                } else {
                    $ttl = isset($fileinfo[$sfile]['title']) && $fileinfo[$sfile]['title'] != "" ? $fileinfo[$sfile]['title'] : str_replace('/', " <i class='fa fa-angle-right text-primary'></i> ", str_replace($dir, "", $sfile));
                    $fhtml .= "<tr><td>{$ttl}</td></tr>";
                }
            }
        }
        $fhtml .= "</table>";
        $siteurl = home_url('/');
        $fhtml .= "<script type='text/javascript' language='JavaScript'> jQuery('.inddl').click(function(){ var tis = this; jQuery.post('{$siteurl}',{wpdmfileid:'{$file['ID']}',wpdmfile:jQuery(this).attr('file'),actioninddlpvr:jQuery(jQuery(this).attr('pass')).val()},function(res){ res = res.split('|'); var ret = res[1]; if(ret=='error') jQuery(jQuery(tis).attr('pass')).addClass('input-error'); if(ret=='ok') location.href=jQuery(tis).attr('rel')+'&_wpdmkey='+res[2];});}); </script> ";
    }
    return $fhtml;
}
Example #4
0
/**
 * @usage Generate downlad link of a package
 * @param $package
 * @param int $embed
 * @param array $extras
 * @return string
 */
function DownloadLink(&$package, $embed = 0, $extras = array())
{
    global $wpdb, $current_user, $wpdm_download_icon, $wpdm_download_lock_icon, $btnclass;
    extract($extras);
    $data = '';
    get_currentuserinfo();
    $package['link_url'] = home_url('/?download=1&');
    $package['link_label'] = !isset($package['link_label']) || $package['link_label'] == '' ? __("Download", "wpdmpro") : $package['link_label'];
    //Change link label using a button image
    $package['link_label'] = apply_filters('wpdm_button_image', $package['link_label'], $package);
    $package['download_url'] = wpdm_download_url($package);
    if (wpdm_is_download_limit_exceed($package['ID'])) {
        $package['download_url'] = '#';
        $package['link_label'] = __('Download Limit Exceeded', 'wpdmpro');
    }
    if (isset($package['expire_date']) && $package['expire_date'] > 0 && $package['expire_date'] < time()) {
        $package['download_url'] = '#';
        $package['link_label'] = __('Download was expired on', 'wpdmpro') . " " . date(get_option('date_format'), $package['expire_date']);
        $package['download_link'] = "<a href='#'>{$package['link_label']}</a>";
        return "<div class='alert alert-warning'><b>" . __('Download:', 'wpdmpro') . "</b><br/>{$package['link_label']}</div>";
    }
    if (isset($package['publish_date']) && $package['publish_date'] > 0 && $package['publish_date'] > time()) {
        $package['download_url'] = '#';
        $package['link_label'] = __('Download will be available from ', 'wpdmpro') . " " . date(get_option('date_format'), $package['publish_date']);
        $package['download_link'] = "<a href='#'>{$package['link_label']}</a>";
        return "<div class='alert alert-warning'><b>" . __('Download:', 'wpdmpro') . "</b><br/>{$package['link_label']}</div>";
    }
    $link_label = isset($package['link_label']) ? $package['link_label'] : __('Download', 'wpdmpro');
    $package['access'] = @maybe_unserialize($package['access']);
    $access = array();
    if (count($access) > 0) {
        foreach ($access as $role) {
            if (!@in_array($role, $package['access'])) {
                $package['access'][] = $role;
            }
        }
    }
    if ($package['download_url'] != '#') {
        $package['download_link'] = "<a class='wpdm-download-link wpdm-download-locked {$btnclass}' rel='noindex nofollow' href='{$package['download_url']}'><i class='{$wpdm_download_icon}'></i>{$link_label}</a>";
    } else {
        $package['download_link'] = "<div class='alert alert-warning'><b>" . __('Download:', 'wpdmpro') . "</b><br/>{$link_label}</div>";
    }
    $caps = array_keys($current_user->caps);
    $role = array_shift($caps);
    $matched = @array_intersect($current_user->roles, @maybe_unserialize($package['access']));
    $skiplink = 0;
    if (is_user_logged_in() && count($matched) <= 0 && !@in_array('guest', @maybe_unserialize($package['access']))) {
        $package['download_url'] = "#";
        $package['download_link'] = stripslashes(get_option('wpdm_permission_msg'));
        $package = apply_filters('download_link', $package);
        if (get_option('_wpdm_hide_all', 0) == 1) {
            $package['download_link'] = 'blocked';
        }
        return $package['download_link'];
    }
    if (!@in_array('guest', @maybe_unserialize($package['access'])) && !is_user_logged_in()) {
        //$loginform = wp_login_form(array('echo' => 0));
        //$loginform = str_replace('class="', 'class="form-control ', $loginform);
        //$loginform = '<a class="wpdm-download-link wpdm-download-login ' . $btnclass . '" href="#wpdm-login-form" data-toggle="modal"><i class=\'glyphicon glyphicon-lock\'></i>' . __('Login', 'wpdmpro') . '</a><div id="wpdm-login-form" class="modal fade">' . $loginform . "</div>";
        $package['download_url'] = wp_login_url($_SERVER['REQUEST_URI']);
        $package['download_link'] = stripcslashes(get_option('wpdm_login_msg'));
        $package['download_link'] = $package['download_link'] == '' ? "<a class='btn btn-danger btn-xs' href='{$package['download_url']}'>" . __('Please login to download', 'wpdmpro') . "</a>" : $package['download_link'];
        return $package['download_link'];
        //get_option('__wpdm_login_form', 0) == 1 ? $loginform : $package['download_link'];die();
    }
    $package = apply_filters('download_link', $package);
    $unqid = uniqid();
    if (!isset($package['quota']) || isset($package['quota']) && $package['quota'] > 0 && $package['quota'] > $package['download_count'] || $package['quota'] == 0) {
        $lock = 0;
        if ($package['password'] != '') {
            $lock = 'locked';
            $data = '
       
        <div id="msg_' . $unqid . '_' . $package['ID'] . '" style="display:none;" class="text-danger">processing...</div>
        <form id="wpdmdlf_' . $unqid . '_' . $package['ID'] . '" method=post action="' . home_url('/') . '" style="margin-bottom:0px;">
        <input type=hidden name="id" value="' . $package['ID'] . '" />
        <input type=hidden name="dataType" value="json" />
        <input type=hidden name="execute" value="wpdm_getlink" />
        <input type=hidden name="action" value="wpdm_ajax_call" />
        ';
            $data .= '
                <div class="input-group" style="max-width:250px;">
        <input type="password" class="form-control input-sm" placeholder="Enter Password" size="10" id="password_' . $unqid . '_' . $package['ID'] . '" name="password" />
        <span class="input-group-btn"><input style="margin-left:5px" id="wpdm_submit_' . $unqid . '_' . $package['ID'] . '" class="wpdm_submit btn btn-sm btn-warning" type="submit" value="' . __('Download', 'wpdmpro') . '" /></span>
            </div>
        </form>        
        
        <script type="text/javascript">
        jQuery("#wpdmdlf_' . $unqid . '_' . $package['ID'] . '").submit(function(){

            jQuery("#msg_' . $unqid . '_' . $package['ID'] . '").html("Processing...").show();
            jQuery("#wpdmdlf_' . $unqid . '_' . $package['ID'] . '").hide();    

            jQuery(this).removeClass("wpdm_submit").addClass("wpdm_submit_wait");

        jQuery(this).ajaxSubmit({
        success: function(res){

                jQuery("#wpdmdlf_' . $unqid . '_' . $package['ID'] . '").hide();
                jQuery("#msg_' . $unqid . '_' . $package['ID'] . '").html("Verifying...").css("cursor","pointer").show().click(function(){ jQuery(this).hide();jQuery("#wpdmdlf_' . $unqid . '_' . $package['ID'] . '").show(); });
                if(res.downloadurl!=""&&res.downloadurl!=undefined) {
                location.href=res.downloadurl;
                jQuery("#wpdmdlf_' . $unqid . '_' . $package['ID'] . '").html("<a style=\'color:#ffffff !important\' class=\'btn btn-success\' href=\'"+res.downloadurl+"\'>Download</a>");
                jQuery("#msg_' . $unqid . '_' . $package['ID'] . '").html("processing...").hide();
                jQuery("#wpdmdlf_' . $unqid . '_' . $package['ID'] . '").show();
                } else {

                    jQuery("#msg_' . $unqid . '_' . $package['ID'] . '").html(""+res.error+"&nbsp;<span class=\'label label-primary\'>Retry</span>").show();;
                }
        }
        });
        return false;
        });
        </script> 
         
        ';
        }
        if ($lock === 'locked') {
            $popstyle = isset($popstyle) && in_array($popstyle, array('modal', 'pop-over')) ? $popstyle : 'pop-over';
            if ($embed == 1) {
                $adata = "" . $data . "";
            } else {
                $adata = '<a href="#pkg_' . $package['ID'] . '" data-title="Download ' . $package['title'] . '" class="wpdm-download-link wpdm-download-locked ' . $popstyle . ' ' . $btnclass . '"><i class=\'' . $wpdm_download_lock_icon . '\'></i>' . $package['link_label'] . '</a>';
                if ($popstyle == 'pop-over') {
                    $adata .= '<div class="modal fade" id="pkg_' . $package['ID'] . '"><div class="row all-locks">' . $data . '</div></div>';
                } else {
                    $adata .= '<div class="modal fade" id="pkg_' . $package['ID'] . '"> <div class="modal-header"><strong style="margin:0px;font-size:12pt">' . __('Download') . '</strong></div><div class="modal-body" styl>' . $data . '</div><div class="modal-footer">' . __('Please take any of the actions above to start download') . '</div></div>';
                }
            }
            $data = $adata;
        }
        if ($lock !== 'locked') {
            $data = $package['download_link'];
        }
    } else {
        $data = "Download limit exceeded!";
    }
    if (!isset($package['files'][0]) || trim($package['files'][0]) == '') {
        return "<div class='alert alert-danger' style='margin: 0;border-radius: 2px'>" . __('No file attached!', 'wpdmpro') . "</div>";
    }
    //return str_replace(array("\r","\n"),"",$data);
    return $data;
}
function wpdm_print_file_list()
{
    if (isset($_POST['action']) && $_POST['action'] == 'wpdmfilelistcd') {
        if (isset($_SESSION['wpdmfilelistcd_' . $_POST['pid']])) {
            $file = wpdm_get_package((int) $_POST['pid']);
            $fhtml = '';
            $idvdl = isset($file['individual_file_download']) ? $file['individual_file_download'] : 0;
            $pd = isset($file['publish_date']) && $file['publish_date'] != "" ? strtotime($file['publish_date']) : 0;
            $xd = isset($file['expire_date']) && $file['expire_date'] != "" ? strtotime($file['expire_date']) : 0;
            $fileinfo = isset($file['fileinfo']) ? $file['fileinfo'] : array();
            $pwdlock = isset($file['password_lock']) ? $file['password_lock'] : 0;
            $olock = wpdm_is_locked($file['ID']) ? 1 : 0;
            $swl = 0;
            if (!isset($file['quota']) || $file['quota'] <= 0) {
                $file['quota'] = 9999999999999;
            }
            if (is_user_logged_in()) {
                $cur[] = 'guest';
            }
            if (!isset($file['access']) || count($file['access']) == 0 || !array_intersect($file['access'], $cur) || wpdm_is_download_limit_exceed($file['ID']) || $file['quota'] <= $file['download_count']) {
                $olock = 1;
            }
            $pwdcol = $dlcol = '';
            if ($pwdlock && $idvdl) {
                $pwdcol = "<th>" . __("Password", "wpdmpro") . "</th>";
            }
            if ($idvdl && ($pwdlock || !$olock)) {
                $dlcol = "<th align=center>" . __("Download", "wpdmpro") . "</th>";
                $swl = 1;
            }
            $dir = get_post_meta($_POST['pid'], '__wpdm_package_dir', true);
            $cd = esc_attr($_POST['cd']);
            $dfiles = array();
            if ($dir != '') {
                $dfiles = wpdm_get_files($dir . $cd, false);
            }
            $fhtml = "<div class='row' id='xfilelist'>";
            if (is_array($dfiles)) {
                foreach ($dfiles as $ind => $sfile) {
                    $ind = WPDM_Crypt::Encrypt($sfile);
                    $fhtml .= "<div class='col-md-4 col-sm-6 col-xs-6'><div class='panel panel-default'>";
                    if (!isset($fileinfo[$sfile]) || !@is_array($fileinfo[$sfile])) {
                        $fileinfo[$sfile] = array();
                    }
                    if (!isset($fileinfo[$sfile]['password'])) {
                        $fileinfo[$sfile]['password'] = "";
                    }
                    if ($fileinfo[$sfile]['password'] == '' && $pwdlock) {
                        $fileinfo[$sfile]['password'] = $file['password'];
                    }
                    $ttl = isset($fileinfo[$sfile]['title']) && $fileinfo[$sfile]['title'] != "" ? $fileinfo[$sfile]['title'] : preg_replace("/([0-9]+)_/", "", basename($sfile));
                    $cttl = is_dir($sfile) ? "<a href='#' class='wpdm-indir' data-dir='{$ttl}' data-pid='{$file['ID']}'>{$ttl}/</a>" : $ttl;
                    $fhtml .= "<div class='panel-heading'>{$cttl}</div>";
                    $imgext = array('png', 'jpg', 'jpeg', 'gif');
                    $ext = explode(".", $sfile);
                    $ext = end($ext);
                    $ext = strtolower($ext);
                    if (is_dir($sfile)) {
                        $ext = 'folder';
                    }
                    $filepath = file_exists($sfile) ? $sfile : UPLOAD_DIR . $sfile;
                    $thumb = "";
                    if (in_array($ext, $imgext)) {
                        $thumb = wpdm_dynamic_thumb($filepath, array(88, 88));
                    }
                    $fticon = WPDM_BASE_URL . 'file-type-icons/' . $ext . '.png';
                    if (!file_exists(WPDM_BASE_DIR . 'file-type-icons/' . $ext . '.png')) {
                        $fticon = WPDM_BASE_URL . 'file-type-icons/ini.png';
                    }
                    if ($thumb) {
                        $fhtml .= "<div class='panel-body text-center'><img class='file-thumb' src='{$thumb}' alt='{$ttl}' /></div><div class='panel-footer'>";
                    } else {
                        $fhtml .= "<div class='panel-body text-center'><img class='file-ico' src='" . $fticon . "' alt='{$ttl}' /></div><div class='panel-footer'>";
                    }
                    if ($swl) {
                        $fileinfo[$sfile]['password'] = $fileinfo[$sfile]['password'] == '' ? $file['password'] : $fileinfo[$sfile]['password'];
                        if ($fileinfo[$sfile]['password'] != '' && $pwdlock && !is_dir($sfile)) {
                            $fhtml .= "<div class='input-group'><input  onkeypress='jQuery(this).removeClass(\"input-error\");' size=10 type='password' value='' id='pass_{$file['ID']}_{$ind}' placeholder='Password' name='pass' class='form-control input-sm inddlps' />";
                        }
                        if ($fileinfo[$sfile]['password'] != '' && $pwdlock && !is_dir($sfile)) {
                            $fhtml .= "<span class='input-group-btn'><button class='inddl btn btn-default btn-sm' file='{$sfile}' rel='" . wpdm_download_url($file) . "&ind=" . $ind . "' pass='******'ID']}_{$ind}'><i class='fa fa-download'></i></button></span></div>";
                        } else {
                            if (!is_dir($sfile)) {
                                $fhtml .= "<a class='btn btn-default btn-sm btn-block' href='" . wpdm_download_url($file) . "&ind=" . $ind . "'><span class='pull-left'><i style='opacity:0.5;margin-top:0px' class='fa fa-download'></i></span>&nbsp;" . __("Download", "wpdmpro") . "</a>";
                            } else {
                                $fhtml .= "<a class='btn btn-default btn-sm btn-block wpdm-indir' href='#'  data-dir='{$ttl}' data-pid='{$file['ID']}'><span class='pull-left'><i style='opacity:0.5;margin-top:0px' class='fa fa-folder'></i></span>&nbsp;" . __("Browse", "wpdmpro") . "</a>";
                            }
                        }
                    }
                    $fhtml .= "</div></div></div>";
                }
            }
            $fhtml .= "</div>";
            echo $fhtml;
        } else {
            die('Session Expired! Please refresh and try again.');
        }
        die;
    }
}
 /**
  * @usage Callback function for [file_list_extended] tag
  * @param $file
  * @return string
  * @usage Generate file list with preview
  */
 public static function Box($file)
 {
     global $current_user;
     $file['files'] = maybe_unserialize($file['files']);
     $fhtml = '';
     $idvdl = \WPDM\Package::isSingleFileDownloadAllowed($file['ID']);
     //isset($file['individual_file_download']) ? $file['individual_file_download'] : 0;
     $pd = isset($file['publish_date']) && $file['publish_date'] != "" ? strtotime($file['publish_date']) : 0;
     $xd = isset($file['expire_date']) && $file['expire_date'] != "" ? strtotime($file['expire_date']) : 0;
     $cur = is_user_logged_in() ? $current_user->roles : array('guest');
     $_SESSION['wpdmfilelistcd_' . $file['ID']] = 1;
     if ($xd > 0 && $xd < time() || $pd > 0 && $pd > time()) {
         $idvdl = 0;
     }
     $dir = isset($file['package_dir']) ? $file['package_dir'] : '';
     $dfiles = array();
     if ($dir != '') {
         $dfiles = wpdm_get_files($dir, false);
     }
     $file['access'] = wpdm_allowed_roles($file['ID']);
     if (count($file['files']) > 0 || count($dfiles) > 0) {
         $fileinfo = isset($file['fileinfo']) ? $file['fileinfo'] : array();
         $pwdlock = isset($file['password_lock']) ? $file['password_lock'] : 0;
         //Check if any other lock option apllied for this package
         $olock = wpdm_is_locked($file['ID']) ? 1 : 0;
         $swl = 0;
         if (!isset($file['quota']) || $file['quota'] <= 0) {
             $file['quota'] = 9999999999999;
         }
         if (is_user_logged_in()) {
             $cur[] = 'guest';
         }
         if (!isset($file['access']) || count($file['access']) == 0 || !wpdm_user_has_access($file['ID']) || wpdm_is_download_limit_exceed($file['ID']) || $file['quota'] <= $file['download_count']) {
             $olock = 1;
         }
         $pwdcol = $dlcol = '';
         if ($pwdlock && $idvdl) {
             $pwdcol = "<th>" . __("Password", "wpdmpro") . "</th>";
         }
         if ($idvdl && ($pwdlock || !$olock)) {
             $dlcol = "<th align=center>" . __("Download", "wpdmpro") . "</th>";
             $swl = 1;
         }
         $allfiles = is_array($file['files']) ? $file['files'] : array();
         //$allfiles = array_merge($allfiles, $dfiles);
         $fhtml = "<div class='row' id='xfilelist'>";
         if (is_array($allfiles)) {
             foreach ($allfiles as $fileID => $sfile) {
                 $fhtml .= "<div class='col-md-4 col-sm-6 col-xs-6'><div class='panel panel-default'>";
                 $ind = \WPDM_Crypt::Encrypt($sfile);
                 if (!isset($fileinfo[$sfile]) || !@is_array($fileinfo[$sfile])) {
                     $fileinfo[$sfile] = array();
                 }
                 if (!@is_array($fileinfo[$fileID])) {
                     $fileinfo[$fileID] = array();
                 }
                 $filePass = isset($fileinfo[$sfile]['password']) ? $fileinfo[$sfile]['password'] : (isset($fileinfo[$fileID]['password']) ? $fileinfo[$fileID]['password'] : '');
                 $fileTitle = isset($fileinfo[$sfile]['title']) && $fileinfo[$sfile]['title'] != '' ? $fileinfo[$sfile]['title'] : (isset($fileinfo[$fileID]['title']) && $fileinfo[$fileID]['title'] != '' ? $fileinfo[$fileID]['title'] : preg_replace("/([0-9]+)_/", "", wpdm_basename($sfile)));
                 if ($filePass == '' && $pwdlock) {
                     $filePass = $file['password'];
                 }
                 $fhtml .= "<div class='panel-heading ttip' title='{$fileTitle}'>{$fileTitle}</div>";
                 $imgext = array('png', 'jpg', 'jpeg', 'gif');
                 $ext = explode(".", $sfile);
                 $ext = end($ext);
                 $ext = strtolower($ext);
                 $filepath = file_exists($sfile) ? $sfile : UPLOAD_DIR . $sfile;
                 $thumb = "";
                 if ($ext == '' || !file_exists(WPDM_BASE_DIR . 'assets/file-type-icons/' . $ext . '.png')) {
                     $ext = '_blank';
                 }
                 if (in_array($ext, $imgext)) {
                     $thumb = wpdm_dynamic_thumb($filepath, array(88, 88));
                 }
                 if ($thumb) {
                     $fhtml .= "<div class='panel-body text-center'><img class='file-thumb' src='{$thumb}' alt='{$fileTitle}' /></div><div class='panel-footer footer-info'>" . wpdm_file_size($sfile) . "</div><div class='panel-footer'>";
                 } else {
                     $fhtml .= "<div class='panel-body text-center'><img class='file-ico' src='" . WPDM_BASE_URL . 'assets/file-type-icons/' . $ext . '.png' . "' alt='{$fileTitle}' /></div><div class='panel-footer footer-info'>" . wpdm_file_size($sfile) . "</div><div class='panel-footer'>";
                 }
                 if ($swl) {
                     if ($filePass != '' && $pwdlock) {
                         $fhtml .= "<div class='input-group'><input  onkeypress='jQuery(this).removeClass(\"input-error\");' size=10 type='password' value='' id='pass_{$file['ID']}_{$ind}' placeholder='Password' name='pass' class='form-control input-sm inddlps' />";
                     }
                     if ($filePass != '' && $pwdlock) {
                         $fhtml .= "<span class='input-group-btn'><button class='inddl btn btn-primary btn-sm' file='{$sfile}' rel='" . wpdm_download_url($file) . "&ind=" . $ind . "' pass='******'ID']}_{$ind}'><i class='fa fa-download'></i></button></span></div>";
                     } else {
                         $fhtml .= "<a class='btn btn-primary btn-sm btn-block' href='" . wpdm_download_url($file) . "&ind=" . $ind . "'><span class='pull-left'><i class='fa fa-download'></i></span>&nbsp;" . __("Download", "wpdmpro") . "</a>";
                     }
                 }
                 $fhtml .= "</div></div></div>";
             }
         }
         if (is_array($dfiles)) {
             foreach ($dfiles as $ind => $sfile) {
                 $ind = \WPDM_Crypt::Encrypt($sfile);
                 $fhtml .= "<div class='col-md-4 col-sm-6 col-xs-6'><div class='panel panel-default'>";
                 if (!isset($fileinfo[$sfile]) || !@is_array($fileinfo[$sfile])) {
                     $fileinfo[$sfile] = array();
                 }
                 if (!isset($fileinfo[$sfile]['password'])) {
                     $fileinfo[$sfile]['password'] = "";
                 }
                 if ($fileinfo[$sfile]['password'] == '' && $pwdlock) {
                     $fileinfo[$sfile]['password'] = $file['password'];
                 }
                 $ttl = isset($fileinfo[$sfile]['title']) && $fileinfo[$sfile]['title'] != "" ? $fileinfo[$sfile]['title'] : preg_replace("/([0-9]+)_/", "", wpdm_basename($sfile));
                 $cttl = is_dir($sfile) ? "<a href='#' class='wpdm-indir' data-dir='{$ttl}' data-pid='{$file['ID']}'>{$ttl}/</a>" : $ttl;
                 $fhtml .= "<div class='panel-heading ttip' title='{$ttl}'>{$cttl}</div>";
                 $imgext = array('png', 'jpg', 'jpeg', 'gif');
                 $ext = explode(".", $sfile);
                 $ext = end($ext);
                 $ext = strtolower($ext);
                 if (is_dir($sfile)) {
                     $ext = 'folder';
                 }
                 $filepath = file_exists($sfile) ? $sfile : UPLOAD_DIR . $sfile;
                 $thumb = "";
                 $showt = 1;
                 if (in_array($ext, $imgext) && apply_filters('file_list_extended_show_thumbs', $showt)) {
                     $thumb = wpdm_dynamic_thumb($filepath, array(88, 88));
                 }
                 $fticon = WPDM_BASE_URL . 'assets/file-type-icons/' . $ext . '.png';
                 if (!file_exists(WPDM_BASE_DIR . 'assets/file-type-icons/' . $ext . '.png')) {
                     $fticon = WPDM_BASE_URL . 'assets/file-type-icons/ini.png';
                 }
                 if ($thumb) {
                     $fhtml .= "<div class='panel-body text-center'><img class='file-thumb' src='{$thumb}' alt='{$ttl}' /></div><div class='panel-footer footer-info'>" . wpdm_file_size($sfile) . "</div><div class='panel-footer'>";
                 } else {
                     $fhtml .= "<div class='panel-body text-center'><img class='file-ico' src='" . $fticon . "' alt='{$ttl}' /></div><div class='panel-footer footer-info'>" . wpdm_file_size($sfile) . "</div><div class='panel-footer'>";
                 }
                 if ($swl) {
                     $fileinfo[$sfile]['password'] = $fileinfo[$sfile]['password'] == '' ? $file['password'] : $fileinfo[$sfile]['password'];
                     if ($fileinfo[$sfile]['password'] != '' && $pwdlock && !is_dir($sfile)) {
                         $fhtml .= "<div class='input-group'><input  onkeypress='jQuery(this).removeClass(\"input-error\");' size=10 type='password' value='' id='pass_{$file['ID']}_{$ind}' placeholder='Password' name='pass' class='form-control input-sm inddlps' />";
                     }
                     if ($fileinfo[$sfile]['password'] != '' && $pwdlock && !is_dir($sfile)) {
                         $fhtml .= "<span class='input-group-btn'><button class='inddl btn btn-primary btn-sm' file='{$sfile}' rel='" . wpdm_download_url($file) . "&ind=" . $ind . "' pass='******'ID']}_{$ind}'><i class='fa fa-download'></i></button></span></div>";
                     } else {
                         if (!is_dir($sfile)) {
                             $fhtml .= "<a class='btn btn-primary btn-sm btn-block' href='" . wpdm_download_url($file) . "&ind=" . $ind . "'><span class='pull-left'><i class='fa fa-download'></i></span>&nbsp;" . __("Download", "wpdmpro") . "</a>";
                         } else {
                             $fhtml .= "<a class='btn btn-primary btn-sm btn-block wpdm-indir' href='#'  data-dir='{$ttl}' data-pid='{$file['ID']}'><span class='pull-left'><i class='fa fa-folder'></i></span> &nbsp;" . __("Browse", "wpdmpro") . "</a>";
                         }
                     }
                 }
                 $fhtml .= "</div></div></div>";
             }
         }
         $fhtml .= "</div>";
         $siteurl = home_url('/');
         $fhtml .= "<script type='text/javascript' language='JavaScript'> jQuery('.inddl').click(function(){ var tis = this; jQuery.post('{$siteurl}',{wpdmfileid:'{$file['ID']}',wpdmfile:jQuery(this).attr('file'),actioninddlpvr:1,filepass:jQuery(jQuery(this).attr('pass')).val()},function(res){ res = res.split('|'); var ret = res[1]; if(ret=='error') jQuery(jQuery(tis).attr('pass')).addClass('input-error'); if(ret=='ok') location.href=jQuery(tis).attr('rel')+'&_wpdmkey='+res[2];});}); </script> ";
     }
     return $fhtml;
 }
function wpdm_block_dllink($package)
{
    global $wpdb, $current_user, $wpdm_download_button_class;
    $uroles = array_keys($current_user->caps);
    $urole = array_shift($uroles);
    get_currentuserinfo();
    $users = maybe_unserialize(get_post_meta($package['ID'], '__wpdm_user_access', true));
    if (!isset($package['access'])) {
        $package['access'] = array();
    }
    if (!$users || is_user_logged_in() && in_array($current_user->roles[0], $package['access']) || in_array('guest', $package['access'])) {
        return $package;
    }
    if (is_user_logged_in() && in_array($current_user->user_login, $users)) {
        $dkey = is_array($package['files']) ? md5(serialize($package['files'])) : md5($package['files']);
        $package['access'] = array('guest');
        $package['download_url'] = wpdm_download_url($package, '');
        if (wpdm_is_download_limit_exceed($package['ID'])) {
            $package['download_url'] = '#';
            $package['link_label'] = __msg('DOWNLOAD_LIMIT_EXCEED');
        }
        $package['download_link'] = $package['download_link_extended'] = "<a class='wpdm-download-link {$wpdm_download_button_class}' rel='noindex nofollow' href='{$package['download_url']}'>{$package['link_label']}</a>";
        return $package;
    } else {
        $package['download_url'] = "#";
        $package['access'] = array();
        $package['download_link'] = $package['download_link_extended'] = stripslashes(get_option('wpdm_permission_msg'));
        if (get_option('_wpdm_hide_all', 0) == 1) {
            $package['download_link'] = $package['download_link_extended'] = 'blocked';
        }
    }
    return $package;
}