Exemplo n.º 1
0
/**
 * @usage Validate individual file password
 */
function wpdm_check_invpass()
{
    if (isset($_POST['actioninddlpvr']) && $_POST['actioninddlpvr'] != '') {
        $fileid = intval($_POST['wpdmfileid']);
        $data = get_post_meta($_POST['wpdmfileid'], '__wpdm_fileinfo', true);
        $data = $data ? $data : array();
        $package = get_post($fileid);
        $packagemeta = wpdm_custom_data($fileid);
        $password = $data[$_POST['wpdmfile']]['password'] != "" ? $data[$_POST['wpdmfile']]['password'] : $packagemeta['password'];
        if ($password == $_POST['actioninddlpvr'] || strpos($password, "[" . $_POST['actioninddlpvr'] . "]") !== FALSE) {
            $id = "__wpu_" . uniqid();
            update_post_meta($fileid, "__wpdmkey_" . $id, 3);
            die("|ok|{$id}|");
        } else {
            die('|error|');
        }
    }
}
$order = isset($params['order']) ? $params['order'] : 'DESC';
$order_fields = array('__wpdm_download_count', '__wpdm_view_count', '__wpdm_package_size_b');
if (!in_array("__wpdm_" . $order_field, $order_fields)) {
    $query_params['orderby'] = $order_field;
    $query_params['order'] = $order;
} else {
    $query_params['orderby'] = 'meta_value_num';
    $query_params['meta_key'] = "__wpdm_" . $order_field;
    $query_params['order'] = $order;
}
$q = new WP_Query($query_params);
$total_files = $q->found_posts;
while ($q->have_posts()) {
    $q->the_post();
    $ext = "_blank";
    $data = wpdm_custom_data(get_the_ID());
    if (isset($data['files']) && count($data['files'])) {
        $tmpavar = $data['files'];
        $tmpvar = array_shift($tmpavar);
        $tmpvar = explode(".", $tmpvar);
        $ext = count($tmpvar) > 1 ? end($tmpvar) : $ext;
    } else {
        $data['files'] = array();
    }
    $ext = isset($data['icon']) && $data['icon'] != '' ? $data['icon'] : $ext . ".png";
    $cats = wp_get_post_terms(get_the_ID(), 'wpdmcategory');
    $fcats = array();
    foreach ($cats as $cat) {
        $fcats[] = "<a class='sbyc' href='{$cfurl}{$cat->slug}'>{$cat->name}</a>";
    }
    $cats = @implode(", ", $fcats);
 /**
  * @usage Process Download Request
  */
 function triggerDownload()
 {
     global $wpdb, $current_user, $wp_query;
     get_currentuserinfo();
     if (!isset($wp_query->query_vars['wpdmdl']) && !isset($_GET['wpdmdl'])) {
         return;
     }
     $id = isset($_GET['wpdmdl']) ? (int) $_GET['wpdmdl'] : (int) $wp_query->query_vars['wpdmdl'];
     if ($id <= 0) {
         return;
     }
     $key = array_key_exists('_wpdmkey', $_GET) ? $_GET['_wpdmkey'] : '';
     $key = $key == '' && array_key_exists('_wpdmkey', $wp_query->query_vars) ? $wp_query->query_vars['_wpdmkey'] : $key;
     $key = preg_replace("/[^_a-z|A-Z|0-9]/i", "", $key);
     $key = "__wpdmkey_" . $key;
     $package = get_post($id, ARRAY_A);
     $package['ID'] = $package['ID'];
     $package = array_merge($package, wpdm_custom_data($package['ID']));
     if (isset($package['files'])) {
         $package['files'] = maybe_unserialize($package['files']);
     } else {
         $package['files'] = array();
     }
     //$package = wpdm_setup_package_data($package);
     $package['access'] = wpdm_allowed_roles($id);
     if (is_array($package)) {
         $role = @array_shift(@array_keys($current_user->caps));
         $cpackage = apply_filters('before_download', $package);
         $lock = '';
         $package = $cpackage ? $cpackage : $package;
         if (isset($package['password_lock']) && $package['password_lock'] == 1) {
             $lock = 'locked';
         }
         if (isset($package['captcha_lock']) && $package['captcha_lock'] == 1) {
             $lock = 'locked';
         }
         if ($lock !== 'locked') {
             $lock = apply_filters('wpdm_check_lock', $lock, $id);
         }
         if (isset($_GET['masterkey']) && esc_attr($_GET['masterkey']) == $package['masterkey']) {
             $lock = 0;
         }
         $limit = $key ? (int) trim(get_post_meta($package['ID'], $key, true)) : 0;
         if ($limit <= 0 && $key != '') {
             delete_post_meta($package['ID'], $key);
         } else {
             if ($key != '') {
                 update_post_meta($package['ID'], $key, $limit - 1);
             }
         }
         $matched = is_array(@maybe_unserialize($package['access'])) && is_user_logged_in() ? array_intersect($current_user->roles, @maybe_unserialize($package['access'])) : array();
         if ($id != '' && is_user_logged_in() && count($matched) < 1 && !@in_array('guest', $package['access']) || !is_user_logged_in() && !@in_array('guest', $package['access']) && $id != '') {
             wpdm_download_data("permission-denied.txt", __("You don't have permission to download this file", 'wpdmpro'));
             die;
         } else {
             if ($lock === 'locked' && $limit <= 0) {
                 if ($key != '') {
                     wpdm_download_data("link-expired.txt", __("Download link is expired. Please get new download link.", 'wpdmpro'));
                 } else {
                     wpdm_download_data("invalid-link.txt", __("Download link is expired or not valid. Please get new download link.", 'wpdmpro'));
                 }
                 die;
             } else {
                 if ($package['ID'] > 0) {
                     include WPDM_BASE_DIR . "wpdm-start-download.php";
                 }
             }
         }
     } else {
         wpdm_notice(__("Invalid download link.", 'wpdmpro'));
     }
 }
Exemplo n.º 4
0
 function Prepare($ID)
 {
     if (isset($this->PackageData['formatted'])) {
         return $this;
     }
     $vars = get_post($ID, ARRAY_A);
     $vars['title'] = stripcslashes($vars['post_title']);
     $vars['description'] = stripcslashes($vars['post_content']);
     $vars['description'] = wpautop(stripslashes($vars['description']));
     $vars['description'] = do_shortcode(stripslashes($vars['description']));
     $vars['excerpt'] = stripcslashes(strip_tags($vars['post_excerpt']));
     $src = wp_get_attachment_image_src(get_post_thumbnail_id($vars['ID']), 'full', false, '');
     $vars['preview'] = $src['0'];
     $vars['create_date'] = isset($vars['post_date']) ? date_i18n(get_option('date_format'), strtotime($vars['post_date'])) : '';
     $vars['categories'] = get_the_term_list($vars['ID'], 'wpdmcategory', '', ', ', '');
     //print_r($vars); die();
     $data = wpdm_custom_data($vars['ID']);
     $vars = array_merge($vars, $data);
     $vars['update_date'] = isset($vars['post_modified']) ? date_i18n(get_option('date_format'), strtotime($vars['post_modified'])) : '';
     //$vars['description'] = apply_filters('the_content',stripslashes($wpdm_package['description']));
     $vars['files'] = get_post_meta($vars['ID'], '__wpdm_files', true);
     $vars['file_count'] = count($vars['files']);
     $vars['file_list'] = wpdm_package_file_list($vars);
     $vars['file_list_extended'] = wpdm_package_file_list_alt($vars);
     $vars['link_label'] = isset($vars['link_label']) ? $vars['link_label'] : __('Download', 'wpdmpro');
     $vars['page_link'] = "<a href='" . get_permalink($vars['ID']) . "'>{$vars['title']}</a>";
     $vars['page_url'] = get_permalink($vars['ID']);
     $tags = get_the_tags($vars['ID']);
     $taghtml = "";
     if (is_array($tags)) {
         foreach ($tags as $tag) {
             $taghtml .= "<a class='btn btn-default btn-xs' style='margin:0 5px 5px 0' href=\"" . get_tag_link($tag->term_id) . "\"><i class='fa fa-tag'></i> &nbsp; " . $tag->name . "</a> &nbsp;";
         }
     }
     $vars['tags'] = $taghtml;
     if (count($vars['files']) > 1) {
         $vars['file_ext'] = 'zip';
     }
     if (is_array($vars['files']) && count($vars['files']) == 1) {
         $tmpdata = explode(".", $vars['files'][0]);
         $vars['file_ext'] = end($tmpdata);
     }
     $vars['file_size'] = wpdm_package_size($vars['ID']);
     //$vars['create_date'] = $vars['create_date']?@date(get_option('date_format'),$vars['create_date']):@date(get_option('date_format'),get_wpdm_meta($vars['ID'],'create_date'));
     //$vars['update_date'] = $vars['update_date']?@date(get_option('date_format'),$vars['update_date']):@date(get_option('date_format'),get_wpdm_meta($vars['ID'],'update_date'));
     $type = get_post_type() != 'wpdmpro' || !array_key_exists(get_option('__wpdm_purl_base', 'download'), $wp_query->query_vars) ? 'link' : 'page';
     $vars['audio_player'] = wpdm_audio_playlist($vars, true);
     $vars['audio_player_single'] = wpdm_audio_player($vars, true);
     //$vars['quick_download'] = wpdm_ddl_button($vars,$type=='link');
     //$vars['email_download'] = wpdm_email_button($vars,$type=='link');
     if (!isset($vars['icon']) || $vars['icon'] == '') {
         if (is_array($vars['files'])) {
             $ifn = @end($vars['files']);
             $ifn = @explode('.', $ifn);
             $ifn = @end($ifn);
         } else {
             $ifn = '_blank';
         }
         $vars['icon'] = '<img class="wpdm_icon" src="' . plugins_url('download-manager/file-type-icons/') . (@count($vars['files']) <= 1 ? $ifn : 'zip') . '.png" onError=\'this.src="' . plugins_url('download-manager/file-type-icons/_blank.png') . '";\' />';
     } else {
         if (!strpos($vars['icon'], '://')) {
             $vars['icon'] = '<img class="wpdm_icon"   src="' . plugins_url($vars['icon']) . '" />';
         } else {
             if (!strpos($vars['icon'], ">")) {
                 $vars['icon'] = '<img class="wpdm_icon"   src="' . $vars['icon'] . '" />';
             }
         }
     }
     if (isset($vars['preview']) && $vars['preview'] != '') {
         $vars['thumb'] = "<img title='' src='" . wpdm_dynamic_thumb($vars['preview'], array(400, 300)) . "'/>";
     } else {
         $vars['thumb'] = $vars['thumb_page'] = $vars['thumb_gallery'] = $vars['thumb_widget'] = "";
     }
     $k = 1;
     $vars['additional_previews'] = isset($vars['more_previews']) ? $vars['more_previews'] : array();
     $img = "<img id='more_previews_{$k}' title='' class='more_previews' src='" . wpdm_dynamic_thumb($vars['preview'], array(575, 170)) . "'/>\n";
     $tmb = "<a href='#more_previews_{$k}' class='spt'><img title='' src='" . wpdm_dynamic_thumb($vars['preview'], array(100, 45)) . "'/></a>\n";
     //WPMS fix
     global $blog_id;
     if (defined('MULTISITE')) {
         $vars['thumb'] = str_replace(home_url('/files'), ABSPATH . 'wp-content/blogs.dir/' . $blog_id . '/files', $vars['thumb']);
     }
     if (!isset($vars['download_link_called'])) {
         $tmpvar = DownloadLink($vars, 0, array('btnclass' => '[btnclass]'));
         $tmpvar1 = DownloadLink($vars, 1);
         $vars['download_link'] = $tmpvar;
         $vars['download_link_extended'] = $tmpvar1;
         $vars['download_link_called'] = 1;
     }
     $vars = apply_filters("wdm_before_fetch_template", $vars);
     if (!isset($vars['formatted'])) {
         $vars['formatted'] = 0;
     }
     ++$vars['formatted'];
     $this->PackageData = $vars;
     return $this;
 }
Exemplo n.º 5
0
 /**
  * @usage Validate individual file password
  */
 function checkFilePassword()
 {
     if (isset($_POST['actioninddlpvr'], $_POST['wpdmfileid']) && $_POST['actioninddlpvr'] != '') {
         $fileid = intval($_POST['wpdmfileid']);
         $data = get_post_meta($_POST['wpdmfileid'], '__wpdm_fileinfo', true);
         $data = $data ? $data : array();
         $package = get_post($fileid);
         $packagemeta = wpdm_custom_data($fileid);
         $password = isset($data[$_POST['wpdmfile']]['password']) && $data[$_POST['wpdmfile']]['password'] != "" ? $data[$_POST['wpdmfile']]['password'] : $packagemeta['password'];
         if ($password == $_POST['filepass'] || strpos($password, "[" . $_POST['filepass'] . "]") !== FALSE) {
             $id = uniqid();
             $_SESSION['_wpdm_unlocked_' . $_POST['wpdmfileid']] = 1;
             update_post_meta($fileid, "__wpdmkey_" . $id, 8);
             die("|ok|{$id}|");
         } else {
             die('|error|');
         }
     }
 }