/** * return download link after verifying password * data format: json */ function wpdm_getlink() { global $wpdb; if (!isset($_POST['id'])) { return; } $id = (int) $_POST['id']; $password = isset($_POST['password']) ? addslashes($_POST['password']) : ''; $file = get_post($id, ARRAY_A); //$file['ID'] = $file['ID']; $file = wpdm_setup_package_data($file); $key = uniqid(); $file1 = $file; // and( password='******' or password like '%[$password]%') $plock = isset($file['password']) && $file['password'] != '' ? 1 : 0; $data = array('error' => '', 'downloadurl' => ''); if (isset($_POST['reCaptchaVerify'])) { $ret = remote_post('https://www.google.com/recaptcha/api/siteverify', array('secret' => get_option('_wpdm_recaptcha_secret_key'), 'response' => $_POST['reCaptchaVerify'], 'remoteip' => $_SERVER['REMOTE_ADDR'])); $ret = json_decode($ret); if ($ret->success == 1) { $_SESSION['_wpdm_unlocked_' . $file['ID']] = 1; update_post_meta($file['ID'], "__wpdmkey_" . $key, 3); $download_url = wpdm_download_url($file, "_wpdmkey={$key}"); $data['downloadurl'] = $download_url; } else { $data['error'] = __("Captcha Verification Failed!", "wpmdpro"); } header("Content-type: application/json"); echo json_encode($data); die; } if ($plock == 1 && $password != $file['password'] && !strpos("__" . $file['password'], "[{$password}]")) { $data['error'] = __('Wrong Password!', 'wpdmpro'); $file = array(); } if ($plock == 1 && $password == '') { $data['error'] = __('Wrong Password!', 'wpdmpro'); $file = array(); } $ux = ""; if ($plock == 1 && isset($file['ID'])) { update_post_meta($file['ID'], "__wpdmkey_" . $key, 3); } if (isset($file['ID']) && $file['ID'] != '') { $pu = isset($file['password_usage']) && is_array($file['password_usage']) ? $file['password_usage'] : array(); $pul = $file['password_usage_limit']; if (is_array($pu) && isset($pu[$password]) && $pu[$password] >= $pul && $pul > 0) { $data['error'] = __('Password usages limit exceeded', 'wpdmpro'); } else { if (!is_array($pu)) { $pu = array(); } $pu[$password] = isset($pu[$password]) ? $pu[$password] + 1 : 1; update_post_meta($file['ID'], '__wpdm_password_usage', $pu); } } if (isset($_COOKIE['unlocked_' . $file1['ID']]) && $_COOKIE['unlocked_' . $file1['ID']] == 1) { $data['error'] = ''; $file = $file1; } if ($data['error'] == '') { $_SESSION['_wpdm_unlocked_' . $file['ID']] = 1; $data['downloadurl'] = wpdm_download_url($file, "_wpdmkey={$key}"); } // home_url('/?downloadkey='.md5($file['files']).'&file='.$id.$ux); $adata = apply_filters("wpdmgetlink", $data, $file); $data = is_array($adata) ? $adata : $data; if (!wpdm_is_ajax()) { @setcookie("wpdm_getlink_data_" . $key, json_encode($data)); if (isset($data['downloadurl']) && $data['downloadurl'] != '') { header("location: " . $data['downloadurl']); die; } header("location: " . $_SERVER['HTTP_REFERER'] . "#nojs_popup|ckid:" . $key); die; } header("Content-type: application/json"); die(json_encode($data)); }
/** * return download link after verifying password * data format: json */ function wpdm_getlink() { global $wpdb; if (!isset($_POST['id'])) { return; } $id = (int) $_POST['id']; $password = isset($_POST['password']) ? addslashes($_POST['password']) : ''; $file = get_post($id, ARRAY_A); //$file['ID'] = $file['ID']; $file = wpdm_setup_package_data($file); $key = uniqid(); $file1 = $file; // and( password='******' or password like '%[$password]%') $plock = isset($file['password_lock']) ? $file['password_lock'] : 0; $data = array('error' => '', 'downloadurl' => ''); if (isset($_POST['reCaptchaVerify'])) { $ret = remote_post('https://www.google.com/recaptcha/api/siteverify', array('secret' => get_option('_wpdm_recaptcha_secret_key'), 'response' => $_POST['reCaptchaVerify'], 'remoteip' => $_SERVER['REMOTE_ADDR'])); $ret = json_decode($ret); if ($ret->success == 1) { $_SESSION['_wpdm_unlocked_' . $file['ID']] = 1; update_post_meta($file['ID'], "__wpdmkey_" . $key, 3); $download_url = wpdm_download_url($file, "_wpdmkey={$key}"); $data['downloadurl'] = $download_url; } else { $data['error'] = __("Captcha Verification Failed!", "wpmdpro"); } header("Content-type: application/json"); echo json_encode($data); die; } if (isset($_POST['verify']) && $_POST['verify'] == 'email' && $file['email_lock'] == 1) { if (wpdm_verify_email($_POST['email'])) { $subject = "Your Download Link"; $site = get_option('blogname'); update_post_meta($file['ID'], "__wpdmkey_" . $key, 3); //file_put_contents(WPDM_CACHE_DIR.'wpdm_'.$key,"3"); $_SESSION['_wpdm_unlocked_' . $file['ID']] = 1; $download_url = wpdm_download_url($file, "_wpdmkey={$key}"); $cff = isset($_POST['custom_form_field']) ? $_POST['custom_form_field'] : array(); $wpdb->insert("{$wpdb->prefix}ahm_emails", array('email' => $_POST['email'], 'pid' => $file['ID'], 'date' => time(), 'custom_data' => serialize($cff))); $eml = get_option('_wpdm_etpl'); $eml['fromname'] = isset($eml['fromname']) ? $eml['fromname'] : get_bloginfo('name'); $eml['frommail'] = isset($eml['frommail']) ? $eml['frommail'] : get_bloginfo('admin_email'); $eml['subject'] = isset($eml['subject']) ? $eml['subject'] : 'Download ' . $file['post_title']; $headers = 'From: ' . $eml['fromname'] . ' <' . $eml['frommail'] . '>' . "\r\nContent-type: text/html\r\n"; $file = wpdm_setup_package_data($file); $file['download_url'] = $download_url; //Custom Download URL for email lock $keys = array(); foreach ($file as $fkey => $value) { $_key = "[{$fkey}]"; $tdata[$_key] = $value; } $tdata["[site_url]"] = home_url('/'); $tdata["[site_name]"] = get_bloginfo('sitename'); $tdata["[download_url]"] = $download_url; $tdata["unsaved:///"] = ""; $tdata["[date]"] = date(get_option('date_format'), time()); $message = $eml['body']; foreach ($tdata as $skey => $svalue) { if (!is_array($svalue)) { $message = str_replace(strval($skey), strval($svalue), $message); $eml['subject'] = str_replace(strval($skey), strval($svalue), $eml['subject']); } } //do something before sending download link do_action("wpdm_before_email_download_link", $_POST, $file); $message = str_replace('[#message#]', stripslashes($message), file_get_contents(wpdm_tpl_path('html-frame.html', WPDM_BASE_DIR . 'email-templates/'))); wp_mail($_POST['email'], stripcslashes($eml['subject']), stripcslashes($message), $headers); $idl = isset($file['email_lock_idl']) ? $file['email_lock_idl'] : 0; if ($idl != 1) { $data['downloadurl'] = ""; $data['error'] = '<div class="alert alert-success">' . __('Download link sent to your email!', 'wpdmpro') . '</div>'; } else { $data['downloadurl'] = $file['download_url']; $data['error'] = ''; $data['msg'] = '<div class="alert alert-success">' . __('Download link also sent to your email!', 'wpdmpro') . '</div>'; } if (!wpdm_is_ajax()) { @setcookie("wpdm_getlink_data_" . $key, json_encode($data)); if (isset($data['downloadurl']) && $data['downloadurl'] != '') { header("location: " . $data['downloadurl']); die; } header("location: " . $_SERVER['HTTP_REFERER'] . "#nojs_popup|ckid:" . $key); die; } header('HTTP/1.0 200 OK'); header("Content-type: application/json"); echo json_encode($data); die; } else { $data['downloadurl'] = ""; $data['error'] = '<div class="alert alert-danger">' . __('Invalid Email Address!', 'wpdmpro') . '</i>'; if (!wpdm_is_ajax()) { @setcookie("wpdm_getlink_data_" . $key, json_encode($data)); if (isset($data['downloadurl']) && $data['downloadurl'] != '') { header("location: " . $data['downloadurl']); die; } header("location: " . $_SERVER['HTTP_REFERER'] . "#nojs_popup|ckid:" . $key); die; } header("Content-type: application/json"); echo json_encode($data); die; } } if (isset($_POST['force']) && $_POST['force'] != '') { $vr = explode('|', base64_decode($_POST['force'])); if ($vr[0] == 'unlocked') { $social = array('f' => 'wpdm_fb_likes', 'g' => 'wpdm_gplus1s', 't' => 'wpdm_tweets', 'l' => 'wpdm_lishare'); if ($_POST['social'] && isset($social[$_POST['social']])) { update_option($social[$_POST['social']], (int) get_option($social[$_POST['social']]) + 1); } update_post_meta($file['ID'], "__wpdmkey_" . $key, 3); $_SESSION['_wpdm_unlocked_' . $file['ID']] = 1; $data['downloadurl'] = wpdm_download_url($file, "_wpdmkey={$key}"); $adata = apply_filters("wpdmgetlink", $data, $file); $data = is_array($adata) ? $adata : $data; if (!wpdm_is_ajax()) { @setcookie("wpdm_getlink_data_" . $key, json_encode($data)); if (isset($data['downloadurl']) && $data['downloadurl'] != '') { header("location: " . $data['downloadurl']); die; } header("location: " . $_SERVER['HTTP_REFERER'] . "#nojs_popup|ckid:" . $key); die; } header("Content-type: application/json"); die(json_encode($data)); } } if ($plock == 1 && $password != $file['password'] && !strpos("__" . $file['password'], "[{$password}]")) { $data['error'] = __('Wrong Password!', 'wpdmpro'); $file = array(); } if ($plock == 1 && $password == '') { $data['error'] = __('Wrong Password!', 'wpdmpro'); $file = array(); } $ux = ""; if ($plock == 1 && isset($file['ID'])) { update_post_meta($file['ID'], "__wpdmkey_" . $key, 3); } if (isset($file['ID']) && $file['ID'] != '') { $pu = isset($file['password_usage']) && is_array($file['password_usage']) ? $file['password_usage'] : array(); $pul = $file['password_usage_limit']; if (is_array($pu) && isset($pu[$password]) && $pu[$password] >= $pul && $pul > 0) { $data['error'] = __('Password usages limit exceeded', 'wpdmpro'); } else { if (!is_array($pu)) { $pu = array(); } $pu[$password] = isset($pu[$password]) ? $pu[$password] + 1 : 1; update_post_meta($file['ID'], '__wpdm_password_usage', $pu); } } if (isset($_COOKIE['unlocked_' . $file1['ID']]) && $_COOKIE['unlocked_' . $file1['ID']] == 1) { $data['error'] = ''; $file = $file1; } if ($data['error'] == '') { $_SESSION['_wpdm_unlocked_' . $file['ID']] = 1; $data['downloadurl'] = wpdm_download_url($file, "_wpdmkey={$key}"); } // home_url('/?downloadkey='.md5($file['files']).'&file='.$id.$ux); $adata = apply_filters("wpdmgetlink", $data, $file); $data = is_array($adata) ? $adata : $data; if (!wpdm_is_ajax()) { @setcookie("wpdm_getlink_data_" . $key, json_encode($data)); if (isset($data['downloadurl']) && $data['downloadurl'] != '') { header("location: " . $data['downloadurl']); die; } header("location: " . $_SERVER['HTTP_REFERER'] . "#nojs_popup|ckid:" . $key); die; } header("Content-type: application/json"); die(json_encode($data)); }
function wdm_ajax_help() { if (isset($_GET['action']) && $_GET['action'] == 'wdm_help') { echo remote_post('http://www.wpdownloadmanager.com/' . $_REQUEST['helpfile'] . '/', array("mode" => "help")); die; } }
function is_valid_license_key() { $key = isset($_POST['_wpdm_license_key']) ? $_POST['_wpdm_license_key'] : get_option('_wpdm_license_key'); update_option("__wpdm_nlc", strtotime('+7 days')); $domain = strtolower(str_replace("www.", "", $_SERVER['HTTP_HOST'])); if (file_exists(dirname(__FILE__) . "/cache/wpdm_{$domain}")) { $data = unserialize(base64_decode(file_get_contents(dirname(__FILE__) . "/cache/wpdm_{$domain}"))); if ($data[0] == md5($domain . $key) && $data[1] > time()) { return true; } else { @unlink(dirname(__FILE__) . "/cache/wpdm_{$domain}"); } } $res = remote_post('http://www.wpdownloadmanager.com/', array('action' => 'wpdm_pp_ajax_call', 'execute' => 'verifylicense', 'domain' => $domain, 'key' => $key, 'product' => 'wpdmpro')); if ($res === 'valid') { file_put_contents(dirname(__FILE__) . "/cache/wpdm_{$domain}", base64_encode(serialize(array(md5($domain . $key), strtotime("+30 days"))))); return true; } if (get_option('settings_ok') == '') { update_option('settings_ok', strtotime('+30 days')); } else { $page = isset($_GET['page']) ? $_GET['page'] : ""; $time = (int) get_option('settings_ok'); if ($time < time() && $page == 'settings' && (!isset($_GET['tab']) || $_GET['tab'] != 'license')) { die("<script>location.href='edit.php?post_type=wpdmpro&page=settings&tab=license';</script>"); } } return false; }