/** * popular_downloads function. * * @access public * @return void */ public function popular_downloads() { $args = array('post_status' => 'publish', 'post_type' => 'dlm_download', 'no_found_rows' => 1, 'posts_per_page' => 10, 'orderby' => 'meta_value', 'order' => 'desc', 'meta_query' => array(array('key' => '_download_count', 'value' => '0', 'compare' => '>')), 'meta_key' => '_download_count', 'fields' => 'ids'); $download_ids = get_posts($args); if (empty($download_ids)) { echo '<p>' . __('There are no stats available yet!', 'download_monitor') . '</p>'; return; } $downloads = array(); foreach ($download_ids as $download_id) { $downloads[$download_id] = get_post_meta($download_id, '_download_count', true); } if ($downloads) { $max_count = max($downloads); } ?> <table class="download_chart" cellpadding="0" cellspacing="0"> <thead> <tr> <th scope="col"><?php _e('Download', "download_monitor"); ?> </th> <th scope="col"><?php _e('Download count', "download_monitor"); ?> </th> </tr> </thead> <tbody> <?php if ($downloads) { foreach ($downloads as $download_id => $count) { $download = new DLM_Download($download_id); $width = $count / ($max_count ? $max_count : 1) * 67; echo '<tr> <th scope="row" style="width:25%;"><a href="' . admin_url('post.php?post=' . $download_id . '&action=edit') . '">' . $download->get_the_title() . '</a></th> <td><span class="bar" style="width:' . $width . '%;"></span>' . number_format($count, 0, '.', ',') . '</td> </tr>'; } } ?> </tbody> </table> <?php }
/** * download_information function. * * @access public * * @param WP_Post $post * * @return void */ public function download_information($post) { global $post; $download = new DLM_Download($post->ID); echo '<div class="dlm_information_panel">'; do_action('dlm_information_start', $download->id); ?> <p> <label for="dlm-info-id"><?php _e('ID', 'download-monitor'); ?> <input type="text" id="dlm-info-id" value="<?php echo $download->id; ?> " readonly /> </label> </p> <p> <label for="dlm-info-url"><?php _e('URL', 'download-monitor'); ?> <input type="text" id="dlm-info-url" value="<?php echo $download->get_the_download_link(); ?> " readonly /> </label> </p> <p> <label for="dlm-info-shortcode"><?php _e('Shortcode', 'download-monitor'); ?> <input type="text" id="dlm-info-shortcode" value='[download id="<?php echo $download->id; ?> "]' readonly /> </label> </p> <?php do_action('dlm_information_end', $download->id); echo '</div>'; }
/** * column_default function. * * @access public * * @param mixed $log * @param mixed $column_name * * @return void */ function column_default($log, $column_name) { switch ($column_name) { case 'status': switch ($log->download_status) { case 'failed': $download_status = '<span class="failed" title="' . esc_attr($log->download_status_message) . '"> </span>'; break; case 'redirected': $download_status = '<span class="redirected" title="' . esc_attr($log->download_status_message) . '"> </span>'; break; default: $download_status = '<span class="completed" title="' . __('Download Complete', 'download-monitor') . '"> </span>'; break; } return $download_status; break; case 'date': return '<time title="' . date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($log->download_date)) . '"">' . sprintf(__('%s ago', 'download-monitor'), human_time_diff(strtotime($log->download_date), current_time('timestamp'))) . '</time>'; break; case 'download': $download = new DLM_Download($log->download_id); $download->set_version($log->version_id); if (!$download->exists()) { $download_string = sprintf(__('Download #%d (no longer exists)', 'download-monitor'), $log->download_id); } else { $download_string = '<a href="' . admin_url('post.php?post=' . $download->id . '&action=edit') . '">'; $download_string .= '#' . $download->id . ' – ' . $download->get_the_title(); $download_string .= '</a>'; } if ($log->version) { $download_string .= ' (' . sprintf(__('v%s', 'download-monitor'), $log->version) . ')'; } return $download_string; break; case 'file': $download = new DLM_Download($log->download_id); $download->set_version($log->version_id); if ($download->exists() && $download->get_the_filename()) { $download_string = '<code>' . $download->get_the_filename() . '</code>'; } else { $download_string = '–'; } return $download_string; break; case 'user': if ($log->user_id) { $user = get_user_by('id', $log->user_id); } if (!isset($user) || !$user) { $user_string = __('Non-member', 'download-monitor'); } else { $user_string = '<a href="' . admin_url('user-edit.php?user_id=' . $user->ID) . '">'; $user_string .= $user->user_login . ' – '; $user_string .= '<a href="mailto:' . $user->user_email . '">'; $user_string .= $user->user_email; $user_string .= '</a>'; } return $user_string; break; case 'user_ip': return '<a href="http://whois.arin.net/rest/ip/' . $log->user_ip . '" target="_blank">' . $log->user_ip . '</a>'; break; case 'user_ua': $ua = $this->uaparser->parse($log->user_agent); return $ua->toFullString; break; } }
/** * custom_columns function. * * @access public * @param mixed $column * @return void */ public function custom_columns($column) { global $post, $download_monitor; $download = new DLM_Download($post->ID); $file = $download->get_file_version(); switch ($column) { case "thumb": echo $download->get_the_image(); break; case "download_id": echo $post->ID; break; case "download_cat": if (!($terms = get_the_term_list($post->ID, 'dlm_download_category', '', ', ', ''))) { echo '<span class="na">–</span>'; } else { echo $terms; } break; case "download_tag": if (!($terms = get_the_term_list($post->ID, 'dlm_download_tag', '', ', ', ''))) { echo '<span class="na">–</span>'; } else { echo $terms; } break; case "featured": if ($download->is_featured()) { echo '<span class="yes">' . __('Yes', 'download-monitor') . '</span>'; } else { echo '<span class="na">–</span>'; } break; case "members_only": if ($download->is_members_only()) { echo '<span class="yes">' . __('Yes', 'download-monitor') . '</span>'; } else { echo '<span class="na">–</span>'; } break; case "redirect_only": if ($download->redirect_only()) { echo '<span class="yes">' . __('Yes', 'download-monitor') . '</span>'; } else { echo '<span class="na">–</span>'; } break; case "file": if ($file) { echo '<a href="' . $download->get_the_download_link() . '"><code>' . $file->filename; if ($size = $download->get_the_filesize()) { echo ' – ' . $size; } echo '</code></a>'; } else { echo '<span class="na">–</span>'; } break; case "version": if ($file && $file->version) { echo $file->version; } else { echo '<span class="na">–</span>'; } break; case "download_count": echo number_format($download->get_the_download_count(), 0, '.', ','); break; case "featured": if ($download->is_featured()) { echo '<img src="' . $download_monitor->plugin_url() . '/assets/images/on.png" alt="yes" />'; } else { echo '<span class="na">–</span>'; } break; } }
/** * export_logs function */ public function export_logs() { global $wpdb; if (empty($_GET['dlm_download_logs'])) { return; } $filter_status = isset($_REQUEST['filter_status']) ? sanitize_text_field($_REQUEST['filter_status']) : ''; $filter_month = !empty($_REQUEST['filter_month']) ? sanitize_text_field($_REQUEST['filter_month']) : ''; $items = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->download_log}\n\t\t \tWHERE type = 'download'\n\t\t \t" . ($filter_status ? "AND download_status = '%s'" : "%s") . "\n\t " . ($filter_month ? "AND download_date >= '%s'" : "%s") . "\n\t " . ($filter_month ? "AND download_date <= '%s'" : "%s") . "\n\t\t \tORDER BY download_date DESC", $filter_status ? $filter_status : "", $filter_month ? date('Y-m-01', strtotime($filter_month)) : "", $filter_month ? date('Y-m-t', strtotime($filter_month)) : "")); $rows = array(); $row = array(); $row[] = __('Download ID', 'download_monitor'); $row[] = __('Version ID', 'download_monitor'); $row[] = __('Filename', 'download_monitor'); $row[] = __('User ID', 'download_monitor'); $row[] = __('User Login', 'download_monitor'); $row[] = __('User Email', 'download_monitor'); $row[] = __('User IP', 'download_monitor'); $row[] = __('User Agent', 'download_monitor'); $row[] = __('Date', 'download_monitor'); $row[] = __('Status', 'download_monitor'); $rows[] = '"' . implode('","', $row) . '"'; if (!empty($items)) { foreach ($items as $item) { $row = array(); $row[] = $item->download_id; $row[] = $item->version_id; $download = new DLM_Download($item->download_id); $download->set_version($item->version_id); if ($download->exists() && $download->get_the_filename()) { $row[] = $download->get_the_filename(); } else { $row[] = '-'; } $row[] = $item->user_id; if ($item->user_id) { $user = get_user_by('id', $item->user_id); } if (!isset($user) || !$user) { $row[] = '-'; $row[] = '-'; } else { $row[] = $user->user_login; $row[] = $user->user_email; } $row[] = $item->user_ip; $row[] = $item->user_agent; $row[] = $item->download_date; $row[] = $item->download_status . ($item->download_status_message ? ' - ' : '') . $item->download_status_message; $rows[] = '"' . implode('","', $row) . '"'; } } $log = implode("\n", $rows); header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=download_log.csv"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Length: " . strlen($log)); echo $log; exit; }
/** * media_browser function. * * @access public * @return void */ public function media_browser() { global $download_monitor; // Enqueue scripts and styles for panel wp_enqueue_script('chosen', $download_monitor->plugin_url() . '/assets/js/chosen/chosen.jquery.min.js'); wp_enqueue_style('chosen', $download_monitor->plugin_url() . '/assets/js/chosen/chosen.css'); wp_enqueue_style('download_monitor_admin_css', $download_monitor->plugin_url() . '/assets/css/admin.css'); wp_enqueue_script('common'); wp_enqueue_style('global'); wp_enqueue_style('wp-admin'); wp_enqueue_style('colors'); wp_enqueue_script('plupload-all'); echo '<!DOCTYPE html><html lang="en"><head><title>' . __('Insert Download', 'download_monitor') . '</title><meta charset="utf-8" />'; do_action('admin_print_styles'); do_action('admin_print_scripts'); do_action('admin_head'); echo '<body id="insert-download" class="wp-core-ui">'; ?> <h2 class="nav-tab-wrapper"> <a href="#insert-shortcode" class="nav-tab nav-tab-active"><?php _e('Insert Shortcode', 'download_monitor'); ?> </a><a href="#quick-add" class="nav-tab"><?php _e('Quick-add download', 'download_monitor'); ?> </a> </h2> <?php // Handle quick-add form if (!empty($_POST['download_url']) && !empty($_POST['download_title']) && wp_verify_nonce($_POST['quick-add-nonce'], 'quick-add')) { $url = stripslashes($_POST['download_url']); $title = sanitize_text_field(stripslashes($_POST['download_title'])); $version = sanitize_text_field(stripslashes($_POST['download_version'])); try { $download = array('post_title' => $title, 'post_content' => '', 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_type' => 'dlm_download'); $download_id = wp_insert_post($download); if ($download_id) { // Meta update_post_meta($download_id, '_featured', 'no'); update_post_meta($download_id, '_members_only', 'no'); update_post_meta($download_id, '_redirect_only', 'no'); update_post_meta($download_id, '_download_count', 0); // File $file = array('post_title' => 'Download #' . $download_id . ' File Version', 'post_content' => '', 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_parent' => $download_id, 'post_type' => 'dlm_download_version'); $file_id = wp_insert_post($file); if (!$file_id) { throw new Exception(__('Error: File was not created.', 'download_monitor')); } // Meta update_post_meta($file_id, '_version', $version); update_post_meta($file_id, '_files', array($url)); update_post_meta($file_id, '_filesize', $download_monitor->get_filesize($url)); echo '<div class="updated"><p>' . __('Download successfully created.', 'download_monitor') . '</p></div>'; } else { throw new Exception(__('Error: Download was not created.', 'download_monitor')); } } catch (Exception $e) { echo '<div class="error"><p>' . $e->getMessage() . "</p></div>"; } } // Get all downloads $downloads = get_posts(array('post_status' => 'publish', 'post_type' => 'dlm_download', 'posts_per_page' => -1)); ?> <form id="insert-shortcode"> <p> <label for="download_id"><?php _e('Choose a download', 'download_monitor'); ?> :</label> <select id="download_id" class="input"> <?php foreach ($downloads as $download) { $download = new DLM_Download($download->ID); echo '<option value="' . $download->id . '">#' . $download->id . ' – ' . $download->get_the_title() . ' – ' . $download->get_the_filename() . '</option>'; } ?> </select> </p> <p> <label for="template_name"><?php _e('Template', 'download_monitor'); ?> :</label> <input type="text" id="template_name" value="" class="input" placeholder="<?php _e('Template Name', 'download_monitor'); ?> " /> <span class="description"> <?php _e('Leaving this blank will use the default <code>content-download.php</code> template file. If you enter, for example, <code>image</code>, the <code>content-download-image.php</code> template will be used instead.', 'download_monitor'); ?> </span> </p> <p> <input type="button" class="button insert_download button-primary button-large" value="<?php _e('Insert Shortcode', 'download_monitor'); ?> " /> </p> </form> <form id="quick-add" action="" method="post"> <!-- Uploader section --> <div id="plupload-upload-ui" class="hide-if-no-js"> <div id="drag-drop-area" style="height:240px"> <div class="drag-drop-inside"> <p class="drag-drop-info"><?php _e('Drop file here', 'download_monitor'); ?> </p> <p><?php _e('or', 'download_monitor'); ?> </p> <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select File', 'download_monitor'); ?> " class="button" /></p> <p><?php _e('or', 'download_monitor'); ?> </p> <p><a href="#" class="add_manually"><?php _e('Enter URL manually', 'download_monitor'); ?> </a></p> </div> </div> </div> <div id="quick-add-details" style="display:none"> <p> <label for="download_url"><?php _e('Download URL', 'download_monitor'); ?> :</label> <input type="text" name="download_url" id="download_url" value="" class="download_url input" placeholder="<?php _e('Required URL', 'download_monitor'); ?> " /> </p> <p> <label for="download_title"><?php _e('Download Title', 'download_monitor'); ?> :</label> <input type="text" name="download_title" id="download_title" value="" class="download_title input" placeholder="<?php _e('Required title', 'download_monitor'); ?> " /> </p> <p> <label for="download_version"><?php _e('Version', 'download_monitor'); ?> :</label> <input type="text" name="download_version" id="download_version" value="" class="input" placeholder="<?php _e('Optional version number', 'download_monitor'); ?> " /> </p> <p> <input type="submit" class="button button-primary button-large" value="<?php _e('Save Download', 'download_monitor'); ?> " /> <?php wp_nonce_field('quick-add', 'quick-add-nonce'); ?> </p> </div> </form> <script type="text/javascript"> jQuery(function() { jQuery('.nav-tab-wrapper a').click(function() { jQuery('#insert-shortcode, #quick-add').hide(); jQuery(jQuery(this).attr('href')).show(); jQuery('a.nav-tab-active').removeClass('nav-tab-active'); jQuery(this).addClass('nav-tab-active'); return false; }); jQuery('#quick-add').hide(); jQuery('#download_id').chosen(); jQuery('body').on('click', '.insert_download', function(){ var win = window.dialogArguments || opener || parent || top; var download_id = jQuery('#download_id').val(); var template = jQuery('#template_name').val(); var shortcode = '[download id="' + jQuery('#download_id').val() + '"'; if ( template ) shortcode = shortcode + ' template="' + template + '"'; shortcode = shortcode + ']'; win.send_to_editor( shortcode ); return false; }); jQuery('.add_manually').click(function() { jQuery('#plupload-upload-ui').slideUp(); jQuery('#quick-add-details').slideDown(); return false; }); <?php $plupload_init = array('runtimes' => 'html5,silverlight,flash,html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', 'file_data_name' => 'async-upload', 'multiple_queues' => false, 'max_file_size' => wp_max_upload_size() . 'b', 'url' => admin_url('admin-ajax.php'), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => __('Allowed Files'), 'extensions' => '*')), 'multipart' => true, 'urlstream_upload' => true, 'multipart_params' => array('_ajax_nonce' => wp_create_nonce('file-upload'), 'action' => 'download_monitor_insert_panel_upload', 'type' => 'dlm_download')); // we should probably not apply this filter, plugins may expect wp's media uploader... $plupload_init = apply_filters('plupload_init', $plupload_init); ?> // create the uploader and pass the config from above var uploader = new plupload.Uploader(<?php echo json_encode($plupload_init); ?> ); // checks if browser supports drag and drop upload, makes some css adjustments if necessary uploader.bind('Init', function(up){ var uploaddiv = jQuery('#plupload-upload-ui'); if ( up.features.dragdrop ) { uploaddiv.addClass('drag-drop'); jQuery('#drag-drop-area') .bind('dragover.wp-uploader', function() { uploaddiv.addClass('drag-over'); }) .bind('dragleave.wp-uploader, drop.wp-uploader', function() { uploaddiv.removeClass('drag-over'); }); } else { uploaddiv.removeClass('drag-drop'); jQuery('#drag-drop-area').unbind('.wp-uploader'); } }); uploader.init(); // a file was added in the queue uploader.bind('FilesAdded', function(up, files) { var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10); plupload.each(files, function(file) { if ( max > hundredmb && file.size > hundredmb && up.runtime != 'html5' ) { // file size error? } else { jQuery('.drag-drop-inside').html('<p><?php _e('Please wait...', 'download_monitor'); ?> </p>'); } }); up.refresh(); up.start(); }); // a file was uploaded uploader.bind('FileUploaded', function( up, file, response ) { jQuery('#quick-add-details').find('input.download_url').val( response.response ); jQuery('#quick-add-details').find('input.download_title').val( basename( response.response ) ); jQuery('#plupload-upload-ui').slideUp(); jQuery('#quick-add-details').slideDown(); }); function basename(path) { return path.split('/').reverse()[0]; } }); </script> <?php echo '</body></html>'; }
} if ($ebd_item->download_id) { if (!$is_new_dm) { $dl = $wpdb->get_row("SELECT * FROM {$wp_dlm_db} WHERE id = " . esc_sql($ebd_item->download_id) . ";"); //another way of getting downloads from download monitor $downloads = get_downloads('include=' . $ebd_item->download_id . ''); $d = new downloadable_file($dl); $file = $downloads[0]->url; //if the link is masked use the real path of the DM file if ($is_masked && function_exists('curl_init')) { $file = $d->filename; } } else { //$file = do_shortcode('[download_data id="'.$ebd_item->download_id.'" data="download_link"]'); if ($is_masked && function_exists('curl_init')) { $dld = new DLM_Download($ebd_item->download_id); $file = $dld->get_file_version()->url; if (!isset($_SERVER['HTTP_RANGE'])) { $dld->get_file_version()->increase_download_count(); } } else { $file = do_shortcode('[download_data id="' . $ebd_item->download_id . '" data="download_link"]'); } } } $wpdb->update($table_link, array("is_downloaded" => 1), array("uid" => esc_sql($dId))); //Check if the cUrl functions are available and the url hide option is enabled. //If not, just rederect to real file url. if ($is_masked && function_exists('curl_init')) { $filesize = 0; if ($dld == null) {
/** * Set cookie * * @param DLM_Download $download */ public static function set_cookie($download) { setcookie(self::KEY, base64_encode(json_encode(array('download' => $download->id, 'version' => $download->get_the_version_number()))), time() + 60, COOKIEPATH, COOKIE_DOMAIN, false, true); }
/** * download_data function. * * @access public * @param mixed $atts * @param mixed $content * @return void */ public function download_data($atts) { global $download_monitor; extract(shortcode_atts(array('id' => '', 'data' => '', 'version_id' => '', 'version' => ''), $atts)); $id = apply_filters('dlm_shortcode_download_id', $id); if (empty($id) || empty($data)) { return; } $download = new DLM_Download($id); if ($version) { $version_id = $download->get_version_id($version); } if ($version_id) { $download->set_version($version_id); } switch ($data) { // File / Version Info case 'filename': return $download->get_the_filename(); case 'filetype': return $download->get_the_filetype(); case 'filesize': return $download->get_the_filesize(); case 'version': return $download->get_the_version_number(); // Download Info // Download Info case 'title': return $download->get_the_title(); case 'short_description': return $download->get_the_short_description(); case 'download_link': return $download->get_the_download_link(); case 'download_count': return $download->get_the_download_count(); case 'post_content': return wpautop(wptexturize(do_shortcode($download->post->post_content))); case 'post_date': return date_i18n(get_option('date_format', $download->post->post_date)); case 'author': return $download->get_the_author(); // Images // Images case 'image': return $download->get_the_image('full'); case 'thumbnail': return $download->get_the_image('thumbnail'); // Taxonomies // Taxonomies case 'tags': return get_the_term_list($id, 'dlm_download_tags', '', ', ', ''); case 'categories': return get_the_term_list($id, 'dlm_download_category', '', ', ', ''); } }
function ebd_process_email_form($cf7) { if (isset($_POST['_wpcf7_download_id'])) { global $wpdb, $wp_dlm_root, $wp_dlm_db, $wp_dlm_db_taxonomies, $def_format, $dlm_url, $downloadurl, $downloadtype, $wp_dlm_db_meta; //compatibility check for the Contact Form 7 plugin $is_new_cf7 = true; if (isset($cf7->posted_data)) { $is_new_cf7 = false; } else { $cf7->posted_data = $_POST; } $is_new_dm = false; $old_rep = error_reporting(E_ERROR | E_PARSE); $pd =& get_file_data(WP_PLUGIN_DIR . "/download-monitor/download-monitor.php", array("Version" => "Version"), 'plugin'); if (!$pd['Version']) { } else { $is_new_dm = true; } $new = error_reporting($old_rep); //table names $table_item = $wpdb->prefix . "ebd_item"; $table_link = $wpdb->prefix . "ebd_link"; $table_posted_data = $wpdb->prefix . "ebd_posted_data"; $delivered_as = get_option('email_before_download_send_email'); $emailFrom = get_option('email_before_download_email_from'); if (isset($_POST['email_from'])) { $emailFrom = htmlspecialchars_decode(urldecode($_POST['email_from'])); } if (strlen($emailFrom) > 0) { $emailFrom = 'From: ' . $emailFrom . "\r\n"; } $use_attachments = get_option('email_before_download_attachment'); if (isset($_POST['delivered_as'])) { $delivered_as = $_POST['delivered_as']; } if (isset($_POST['attachment'])) { $use_attachments = trim($_POST['attachment']) == 'yes'; } //check if email is allowed $email = $cf7->posted_data['your-email']; //compare email againts not allowed domains. $forbidden_domains = get_option('email_before_download_forbidden_domains'); $domains = explode(',', $forbidden_domains); if (check_domains($email, $domains)) { $id = (int) $_POST['_wpcf7']; $unit_tag = $_POST['_wpcf7_unit_tag']; $items = array('mailSent' => false, 'into' => '#' . $unit_tag, 'captcha' => null); //error message $items['message'] = "The email that you provided is not allowed. Please provide another one."; $on_sent_ok = $cf7->additional_setting('on_sent_ok', false); $items['onSentOk'] = $on_sent_ok; $echo = json_encode($items); @header('Content-Type: application/json; charset=' . get_option('blog_charset')); echo $echo; die; } //get selected downloads $dIds = $_POST['ebd_downloads']; $dl_items = array(); $multipleLinks = ''; $message_mult = ''; $attachments = array(); $time_requested = time(); $target = '_blank'; //get all download monitor objects if ($dIds) { foreach ($dIds as $id) { if (!$is_new_dm) { $dl_it = $wpdb->get_row("SELECT * FROM {$wp_dlm_db} WHERE id = '" . esc_sql($id) . "';"); $dl_items[] = new downloadable_file($dl_it); } else { $dl_it = new stdClass(); //$dl_it->title = do_shortcode('[download_data id="'.$id.'" data="title"]'); //$d->url = do_shortcode('[download_data id="'.$id.'" data="filename"]'); $dl_tmp = new DLM_Download($id); $dl_it->title = $dl_tmp->get_the_title(); $dl_it->filename = $dl_tmp->get_file_version()->url; $dl_it->id = $id; $dl_items[] = $dl_it; } } } //get edb items: it's common for all $dId = $_POST['_wpcf7_download_id']; $ebd_item = $wpdb->get_row("SELECT * FROM {$table_item} WHERE id = '" . esc_sql($dId) . "';"); $d = null; $dl = null; //get single download, multible are comma separated so the $dl for this will be NULL if (!$is_new_dm) { $dl = $wpdb->get_row("SELECT * FROM {$wp_dlm_db} WHERE id = '" . esc_sql($ebd_item->download_id) . "';"); $d = new downloadable_file($dl); } else { $d = new stdClass(); $dl_tmp = new DLM_Download($ebd_item->download_id); $d->title = $dl_tmp->get_the_title(); $d->filename = $dl_tmp->get_file_version()->url; } //variable for the title it wll be used only for the single downloads and the email subject $title = ''; $title = $ebd_item->title; if ($title == NULL || $title == '') { if ($ebd_item->file) { $title = basename($ebd_item->file); } else { $title = $d->title; } } $url = ''; //titles and urls for multiple $titles = array(); $urls = array(); $innerHtml = ''; //if checkboxes were selected if (count($dl_items) > 0) { foreach ($dl_items as $dl_item) { //generate unique id for the file (link) $uid = md5(uniqid(rand(), true)); //expiration date if needed if it's 0 or NULL the link will never expire $expireAt = 0; if (get_option('email_before_download_expire_time') != NULL && get_option('email_before_download_expire_time') != "0") { $expireAt = strtotime(get_option('email_before_download_expire_time')); } $link_data = array(); $link_data['uid'] = $uid; $link_data['selected_id'] = $dl_item->id; $link_data['expire_time'] = $expireAt; $link_data['time_requested'] = $time_requested; $link_data['email'] = $cf7->posted_data['your-email']; $link_data['item_id'] = $_POST['_wpcf7_download_id']; $link_data['delivered_as'] = $delivered_as; if (isset($_POST['masked'])) { $link_data['is_masked'] = $_POST['masked']; } $wpdb->insert($table_link, $link_data); // $url = WP_PLUGIN_URL . "/email-before-download/download.php?dl=" . $uid; $titles[] = $dl_item->title; $title = implode($titles, '|'); if (isset($_POST['format'])) { $link = do_shortcode('[download id="' . $dl_item->id . '" format="' . $_POST['format'] . '"]'); $innerHtml .= $link . '<br />'; } else { $innerHtml .= '<a class="icon-button download-icon" target="' . $target . '" href="' . $url . '"><span class="et-icon"><span>' . addslashes($dl_item->title) . '</span></span></a><br />'; } // if(get_option('email_before_download_send_email') == 'Send Email' || get_option('email_before_download_send_email') == 'Both'){ // } if ($use_attachments) { $dirs = wp_upload_dir(); $uploadpath = trailingslashit($dirs['baseurl']); $absuploadpath = trailingslashit($dirs['basedir']); $attachment = NULL; if ($uploadpath && (strstr($dl_item->filename, $uploadpath) || strstr($dl_item->filename, $absuploadpath))) { $file = str_replace($uploadpath, "", $dl_item->filename); if (is_file($absuploadpath . $file)) { $attachment = $absuploadpath . $file; } } $attachments[] = $attachment; } } } else { if (!empty($d) || !empty($ebd_item->file)) { //generate unique id for the file (link) $uid = md5(uniqid(rand(), true)); //expiration date if needed if it's 0 or NULL the link will never expire $expireAt = 0; if (get_option('email_before_download_expire_time') != NULL && get_option('email_before_download_expire_time') != "0") { $expireAt = strtotime(get_option('email_before_download_expire_time')); } $link_data = array(); $link_data['uid'] = $uid; $link_data['expire_time'] = $expireAt; $link_data['time_requested'] = $time_requested; $link_data['email'] = $cf7->posted_data['your-email']; $link_data['item_id'] = $_POST['_wpcf7_download_id']; $link_data['delivered_as'] = $delivered_as; $link_data['selected_id'] = 0; if (isset($_POST['masked'])) { $link_data['is_masked'] = $_POST['masked']; } if (isset($_POST['force_download'])) { $link_data['is_force_download'] = $_POST['force_download']; } $wpdb->insert($table_link, $link_data); if (isset($_POST['format']) && $ebd_item->download_id != NULL) { $link = do_shortcode('[download id="' . $ebd_item->download_id . '" format="' . $_POST['format'] . '"]'); $innerHtml .= $link . '<br />'; } else { $url = WP_PLUGIN_URL . "/email-before-download/download.php?dl=" . $uid; $innerHtml = '<a class="icon-button download-icon" target="' . $target . '" href="' . $url . '"><span class="et-icon"><span>' . addslashes($title) . '</span></span></a><br />'; } } else { //we don't sent an email and throw an error $cf7->skip_mail = true; //this message doesn't seem to appear but we leave it for now if ($is_new_cf7) { $additional_settings = $cf7->prop('additional_settings'); $additional_settings .= "on_sent_ok: \"document.getElementById('wpm_download_{$dId}').style.display = 'inline'; document.getElementById('wpm_download_{$dId}').innerHTML='You should select the files to dowload.'; \""; $cf7->set_properties(array('additional_settings' => $additional_settings)); } else { $cf7->additional_settings .= "on_sent_ok: \"document.getElementById('wpm_download_{$dId}').style.display = 'inline'; document.getElementById('wpm_download_{$dId}').innerHTML='You should select the files to dowload.'; \""; } $id = (int) $_POST['_wpcf7']; $unit_tag = $_POST['_wpcf7_unit_tag']; $items = array('mailSent' => false, 'into' => '#' . $unit_tag, 'captcha' => null); //error message $items['message'] = "Please select at least one of the documents"; $on_sent_ok = $cf7->additional_setting('on_sent_ok', false); $items['onSentOk'] = $on_sent_ok; $echo = json_encode($items); @header('Content-Type: application/json; charset=' . get_option('blog_charset')); echo $echo; die; } } $cf7->posted_data['your-message'] = 'The downloaded file name(s): ' . $title; if ($is_new_cf7) { $mail = $cf7->prop('mail'); if (strpos($mail['body'], "[your-message]") === false) { $mail['body'] = $mail['body'] . "\nThe downloaded file name: {$title};"; $cf7->posted_data['your-message'] = $title; } else { $mbody = $mail['body']; $mail['body'] = str_replace("[your-message]", 'The downloaded file name(s): ' . $title, $mbody); } $cf7->set_properties(array('mail' => $mail)); } else { if (strpos($cf7->mail['body'], "[your-message]") === false) { $cf7->posted_data['your-message'] = $title; $cf7->mail['body'] = $cf7->mail['body'] . "\nThe downloaded file name: [your-message]"; } } $target = get_option('email_before_download_link_target'); $html_before = get_option('email_before_download_html_before_link'); $html_after = get_option('email_before_download_html_after_link'); //if multiple files are downloaded ??? $message = ''; if (count($dl_items) > 0) { $email_template = get_option('email_before_download_email_template_mult'); if (strlen(trim($email_template)) > 0) { $message = str_replace(array('[requesting_name]', '[file_urls]'), array($cf7->posted_data['your-name'], $innerHtml), trim($email_template)); } else { $message = $innerHtml; } } else { $email_template = get_option('email_before_download_email_template'); if (strlen(trim($email_template)) > 0) { if (isset($_POST['format']) && $ebd_item->download_id != NULL) { $message = 'You requested: ' . $innerHtml; } else { $message = str_replace(array('[requesting_name]', '[file_url]', '[file_name]'), array($cf7->posted_data['your-name'], $url, $title), trim($email_template)); } } else { if (isset($_POST['format']) && $ebd_item->download_id != NULL) { $message = 'You requested: ' . $innerHtml; } else { $message = '<a class="icon-button download-icon" target="' . $target . '" href="' . $url . '">' . $title . '</a>'; } } } $innerHtml = $html_before . $innerHtml . $html_after; if ($delivered_as == 'Send Email') { // $attachments = NULL; if ($use_attachments && count($dl_items) == 0) { $dirs = wp_upload_dir(); $uploadpath = trailingslashit($dirs['baseurl']); $absuploadpath = trailingslashit($dirs['basedir']); $attachment = NULL; if ($uploadpath && (strstr($d->filename, $uploadpath) || strstr($d->filename, $absuploadpath))) { $file = str_replace($uploadpath, "", $d->filename); if (is_file($absuploadpath . $file)) { $attachment = $absuploadpath . $file; } } $attachments = array($attachment); } if (count($attachments) == 0) { $attachments = NULL; } $email_subject = get_option('email_before_download_subject'); if (strlen(trim($email_subject)) > 0) { $email_subject = str_replace('[files]', $title, $email_subject); } else { $email_subject = 'Requested URL for the file(s): ' . $title; } //email_before_download_subject @wp_mail($cf7->posted_data['your-email'], $email_subject, stripslashes($message), $emailFrom . "Content-Type: text/html\n", $attachments); if ($is_new_cf7) { $additional_settings = $cf7->prop('additional_settings'); $additional_settings .= "\n" . "on_sent_ok: \"document.getElementById('wpm_download_{$dId}').style.display = 'inline'; document.getElementById('wpm_download_{$dId}').innerHTML='The link to the file(s) has been emailed to you.'; \""; $cf7->set_properties(array('additional_settings' => $additional_settings)); } else { $cf7->additional_settings .= "\n" . "on_sent_ok: \"document.getElementById('wpm_download_{$dId}').style.display = 'inline'; document.getElementById('wpm_download_{$dId}').innerHTML='The link to the file(s) has been emailed to you.'; \""; } } else { if ($delivered_as == 'Both') { //$attachments = NULL; if ($use_attachments && count($dl_items) == 0) { $dirs = wp_upload_dir(); $uploadpath = trailingslashit($dirs['baseurl']); $absuploadpath = trailingslashit($dirs['basedir']); $attachment = NULL; if ($uploadpath && (strstr($d->filename, $uploadpath) || strstr($d->filename, $absuploadpath))) { $file = str_replace($uploadpath, "", $d->filename); if (is_file($absuploadpath . $file)) { $attachment = $absuploadpath . $file; } } $attachments = array($attachment); } if (count($attachments) == 0) { $attachments = NULL; } $email_subject = get_option('email_before_download_subject'); if (strlen(trim($email_subject)) > 0) { $email_subject = str_replace('[files]', $title, $email_subject); } else { $email_subject = 'Requested URL for the file(s): ' . $title; } @wp_mail($cf7->posted_data['your-email'], $email_subject, $message, $emailFrom . "Content-Type: text/html\n", $attachments); if ($is_new_cf7) { $additional_settings = $cf7->prop('additional_settings'); $additional_settings .= "\n" . "on_sent_ok: \"document.getElementById('wpm_download_{$dId}').style.display = 'inline'; document.getElementById('wpm_download_{$dId}').innerHTML='{$innerHtml}'; \""; $cf7->set_properties(array('additional_settings' => $additional_settings)); } else { $cf7->additional_settings .= "\n" . "on_sent_ok: \"document.getElementById('wpm_download_{$dId}').style.display = 'inline'; document.getElementById('wpm_download_{$dId}').innerHTML='{$innerHtml}'; \""; } } else { if ($is_new_cf7) { $additional_settings = $cf7->prop('additional_settings'); $additional_settings .= "\n" . "on_sent_ok: \"document.getElementById('wpm_download_{$dId}').style.display = 'inline'; document.getElementById('wpm_download_{$dId}').innerHTML='{$innerHtml}'; \""; $cf7->set_properties(array('additional_settings' => $additional_settings)); } else { $cf7->additional_settings .= "\n" . "on_sent_ok: \"document.getElementById('wpm_download_{$dId}').style.display = 'inline'; document.getElementById('wpm_download_{$dId}').innerHTML='{$innerHtml}'; \""; } } } // save the extra form information into the xml $xml = new SimpleXMLElement('<posted_data></posted_data>'); foreach ($cf7->posted_data as $key => $value) { if (is_array($value)) { $value = implode(',', $value); } $xml->addChild($key, htmlentities($value, ENT_QUOTES, 'utf-8')); //encode some chars like '&' } $posted_data = array(); $posted_data['time_requested'] = $time_requested; $posted_data['posted_data'] = $xml->asXML(); $posted_data['email'] = $cf7->posted_data['your-email']; $posted_data['user_name'] = $cf7->posted_data['your-name']; $wpdb->insert($table_posted_data, $posted_data); } return $cf7; }
function pmprodlm_shortcode_download_content($content, $download_id, $atts) { global $current_user; if (empty($atts['template']) && function_exists('pmpro_hasMembershipLevel')) { if (!pmpro_has_membership_access($download_id)) { $dlm_download = new DLM_Download($download_id); if ($dlm_download->exists()) { $download_membership_levels = pmprodlm_getDownloadLevels($dlm_download); $content .= '<a href="'; if (count($download_membership_levels[0]) > 1) { $content .= pmpro_url('levels'); } else { $content .= pmpro_url("checkout", "?level=" . $download_membership_levels[0][0], "https"); } $content .= '">' . $dlm_download->get_the_title() . '</a>'; $content .= ' (' . __('Membership Required', 'pmprodlm') . ': ' . $download_membership_levels[1] . ')'; $content = apply_filters("pmprodlm_shortcode_download_content_filter", $content); } else { $content = '[' . __('Download not found', 'download-monitor') . ']'; } } } return $content; }