Email Before Download - Version 5.1.2

Version Description

Download this release

Release Info

Developer mandsconsulting
Plugin Icon 128x128 Email Before Download
Version 5.1.2
Comparing to
See all releases

Code changes from version 5.1.1 to 5.1.2

email-before-download.php CHANGED
@@ -11,7 +11,7 @@
11
  * @wordpress-plugin
12
  * Plugin Name: Email Before Download
13
  * Plugin URI: mandsconsulting.com
14
- * Version: 5.1.1
15
  * Author: M&S Consulting
16
  * Author URI: mandsconsulting.com
17
  * License: GPL-2.0+
@@ -24,15 +24,7 @@ if ( ! defined( 'WPINC' ) ) {
24
  die;
25
  }
26
 
27
- define( 'PLUGIN_NAME_VERSION', '5.1.1' );
28
-
29
- //if Contact Form 7 version isn't in standard format, make it so.
30
- if(strlen(WPCF7_VERSION) == 3){
31
- define( 'DEPENDENCY_MIN_VERSION', WPCF7_VERSION.'.0' );
32
- }else {
33
- define( 'DEPENDENCY_MIN_VERSION', WPCF7_VERSION );
34
-
35
- }
36
 
37
  function activate_email_before_download() {
38
  require_once plugin_dir_path( __FILE__ ) . 'includes/class-email-before-download-activator.php';
11
  * @wordpress-plugin
12
  * Plugin Name: Email Before Download
13
  * Plugin URI: mandsconsulting.com
14
+ * Version: 5.1.2
15
  * Author: M&S Consulting
16
  * Author URI: mandsconsulting.com
17
  * License: GPL-2.0+
24
  die;
25
  }
26
 
27
+ define( 'PLUGIN_NAME_VERSION', '5.1.2' );
 
 
 
 
 
 
 
 
28
 
29
  function activate_email_before_download() {
30
  require_once plugin_dir_path( __FILE__ ) . 'includes/class-email-before-download-activator.php';
includes/class-email-before-download-activator.php CHANGED
@@ -67,8 +67,6 @@ class Email_Before_Download_Activator
67
  foreach ($tables as $table) {
68
  dbDelta($table . $charset_collate);
69
  }
70
-
71
-
72
  }
73
 
74
  }
67
  foreach ($tables as $table) {
68
  dbDelta($table . $charset_collate);
69
  }
 
 
70
  }
71
 
72
  }
includes/class-email-before-download-db.php CHANGED
@@ -50,6 +50,7 @@ class Email_Before_Download_DB
50
 
51
  public function item_exists($data)
52
  {
 
53
  //check if item exists and if it needs updated
54
  $query = $this->db->get_row("SELECT * FROM $this->item_table WHERE download_id = '" . $data['download_id'] . "'");
55
  if (count($query) > 0) {
@@ -151,4 +152,34 @@ class Email_Before_Download_DB
151
  }
152
  return $csv;
153
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
50
 
51
  public function item_exists($data)
52
  {
53
+
54
  //check if item exists and if it needs updated
55
  $query = $this->db->get_row("SELECT * FROM $this->item_table WHERE download_id = '" . $data['download_id'] . "'");
56
  if (count($query) > 0) {
152
  }
153
  return $csv;
154
  }
155
+ public function get_ajax_links($email){
156
+ $time = time() - 10;
157
+
158
+ $linkQuery = "
159
+ SELECT uid, selected_id
160
+ FROM $this->link_table
161
+ WHERE email = '$email'
162
+ AND time_requested > $time
163
+ ";
164
+ $links = $this->db->get_results($linkQuery);
165
+
166
+ return $links;
167
+ }
168
+ public function skip_check($downloadID) {
169
+ $sql = "
170
+ SELECT *
171
+ FROM $this->item_table
172
+ WHERE download_id = $downloadID
173
+ OR download_id LIKE ',$downloadID'
174
+ OR download_id LIKE '$downloadID,'
175
+ OR download_id LIKE ',$downloadID,'";
176
+
177
+ $query = $this->db->get_results($sql);
178
+
179
+ if(count($query) < 1){
180
+ return false;
181
+ }
182
+ return true;
183
+ }
184
+
185
  }
includes/class-email-before-download-downloader.php CHANGED
@@ -18,23 +18,9 @@ class Email_Before_download_Downloader
18
  $this->version = $version;
19
 
20
  }
21
-
22
- public function parse($wp)
23
- {
24
- if (isset($wp->query_vars['pagename'])) {
25
- $pagename = $wp->query_vars['pagename'];
26
- } else {
27
- return;
28
- }
29
- if (($pagename == 'ebd-file') && (isset($_GET['uid']))) {
30
- $uid = sanitize_text_field($_GET['uid']);
31
- $this->serve_file($uid);
32
- }
33
- }
34
-
35
-
36
  public function serve_file($uid)
37
  {
 
38
  $db = new Email_Before_Download_DB();
39
  $link = $db->select_link('uid', $uid);
40
  if ($this->expired($link)) {
@@ -47,9 +33,8 @@ class Email_Before_download_Downloader
47
 
48
  }
49
  $db->mark_downloaded($link->id);
50
- wp_redirect($file);
51
- exit();
52
-
53
  }
54
 
55
  public function expired($link)
@@ -58,7 +43,4 @@ class Email_Before_download_Downloader
58
  if ($link->expire_time < time()) return true;
59
  return false;
60
  }
61
- public function update_link($download, $version) {
62
-
63
- }
64
  }
18
  $this->version = $version;
19
 
20
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  public function serve_file($uid)
22
  {
23
+
24
  $db = new Email_Before_Download_DB();
25
  $link = $db->select_link('uid', $uid);
26
  if ($this->expired($link)) {
33
 
34
  }
35
  $db->mark_downloaded($link->id);
36
+ wp_redirect($file);
37
+ exit();
 
38
  }
39
 
40
  public function expired($link)
43
  if ($link->expire_time < time()) return true;
44
  return false;
45
  }
 
 
 
46
  }
includes/class-email-before-download-form.php CHANGED
@@ -25,6 +25,7 @@ class Email_Before_Download_Form
25
 
26
  public function html()
27
  {
 
28
  $raw = do_shortcode("[contact-form-7 id=\"$this->form_id\" ]");
29
  $remove = array('<ebd />','<ebd/>','<ebd_left />','<ebd_left/>');
30
  $raw = str_replace($remove, "", $raw);
@@ -36,20 +37,7 @@ class Email_Before_Download_Form
36
  $formID = $parent->getAttribute('action');
37
  $tmp = explode('#', $formID);
38
  $this->atts['form_id'] = $tmp[1];
39
- $children = $parent->getElementsByTagName('input');
40
- $paragraphs = $parent->getElementsByTagName('p');
41
- foreach ($paragraphs as $p){
42
- $p->setAttribute('class',$p->getAttribute('class') .' cf7_input');
43
- if(($this->atts['hide_form'] == 'yes') && ($this->atts['checked'] == '')){
44
- $parent->setAttribute('id','downloadinputform');
45
- if(count($this->download_id) > 1)
46
- $p->setAttribute('style','display:none');
47
- }
48
- }
49
- $paragraph = $parent->getElementsByTagName('p')->item(0);
50
- if($this->atts['hide_form'] != 'no') {
51
- $paragraph->setAttribute('id','downloadinputform');
52
- }
53
 
54
  foreach ($this->download_id as $key => $id) {
55
  if(count($this->download_id) == 1) {
@@ -59,39 +47,24 @@ class Email_Before_Download_Form
59
  }
60
  $item = $form->importNode($item, true);
61
  $paragraph->parentNode->insertBefore($item, $paragraph);
62
-
63
  }
64
 
65
  foreach ($this->atts as $name => $value) {
66
  if($value){
67
  $item = $this->hidden_dom_obj($name,$value);
68
  $item = $form->importNode($item, true);
69
- $children->item(0)->parentNode->insertBefore($item, $children->item(0));
70
  }
71
  }
72
  if($this->atts['hide_form'] == 'yes'){
73
  $script = $this->jquery_dom_obj();
74
  $item = $form->importNode($script, true);
75
  $parent->appendChild($item);
76
-
77
-
78
  }
79
  libxml_clear_errors();
80
  return $form->saveHTML();
81
-
82
  }
83
 
84
- private function hide_form($form){
85
- $userCss = get_option('email_before_download_hidden_form_css');
86
- if($userCss == ''){
87
- $form->setAttribute('style','display:none');
88
- }else{
89
- $class = $form->getAttribute('class');
90
- $class = $class . " ". $userCss;
91
- $form->setAttribute('class',$class);
92
- }
93
- return $form;
94
- }
95
  private function download_dom_obj($id, $key){
96
 
97
  $formObject = new DOMDocument();
@@ -125,11 +98,16 @@ class Email_Before_Download_Form
125
  return $node->item(0);
126
  }
127
  private function jquery_dom_obj(){
 
128
  $formObject = new DOMDocument();
129
  $formID = $this->atts['form_id'];
130
  $formSelector = str_replace('-','',$formID);
131
  $formObject->formatOutput = true;
 
 
 
132
  $script = "<script> var ". $formSelector. "selectors = \"div#$formID > form > .ebd_input > input\";
 
133
  jQuery( ". $formSelector. "selectors ).on( \"click\", function () {
134
  var ". $formSelector. "n = jQuery( ". $formSelector. "selectors+\":checked\" ).length;
135
 
25
 
26
  public function html()
27
  {
28
+
29
  $raw = do_shortcode("[contact-form-7 id=\"$this->form_id\" ]");
30
  $remove = array('<ebd />','<ebd/>','<ebd_left />','<ebd_left/>');
31
  $raw = str_replace($remove, "", $raw);
37
  $formID = $parent->getAttribute('action');
38
  $tmp = explode('#', $formID);
39
  $this->atts['form_id'] = $tmp[1];
40
+ $paragraph = $parent->getElementsByTagName('div')->item(0);
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  foreach ($this->download_id as $key => $id) {
43
  if(count($this->download_id) == 1) {
47
  }
48
  $item = $form->importNode($item, true);
49
  $paragraph->parentNode->insertBefore($item, $paragraph);
 
50
  }
51
 
52
  foreach ($this->atts as $name => $value) {
53
  if($value){
54
  $item = $this->hidden_dom_obj($name,$value);
55
  $item = $form->importNode($item, true);
56
+ $paragraph->parentNode->insertBefore($item, $paragraph);
57
  }
58
  }
59
  if($this->atts['hide_form'] == 'yes'){
60
  $script = $this->jquery_dom_obj();
61
  $item = $form->importNode($script, true);
62
  $parent->appendChild($item);
 
 
63
  }
64
  libxml_clear_errors();
65
  return $form->saveHTML();
 
66
  }
67
 
 
 
 
 
 
 
 
 
 
 
 
68
  private function download_dom_obj($id, $key){
69
 
70
  $formObject = new DOMDocument();
98
  return $node->item(0);
99
  }
100
  private function jquery_dom_obj(){
101
+ $hide = "";
102
  $formObject = new DOMDocument();
103
  $formID = $this->atts['form_id'];
104
  $formSelector = str_replace('-','',$formID);
105
  $formObject->formatOutput = true;
106
+ if(($this->atts['hide_form'] == 'yes') && ($this->atts['checked'] == '') && (count($this->download_id) > 1) )
107
+ $hide = "jQuery(\"div#$formID form \").children().not('.ebd_input').not('.wpcf7-response-output').hide();";
108
+
109
  $script = "<script> var ". $formSelector. "selectors = \"div#$formID > form > .ebd_input > input\";
110
+ $hide
111
  jQuery( ". $formSelector. "selectors ).on( \"click\", function () {
112
  var ". $formSelector. "n = jQuery( ". $formSelector. "selectors+\":checked\" ).length;
113
 
includes/class-email-before-download-process.php CHANGED
@@ -35,27 +35,6 @@ class Email_Before_Download_Process
35
  }
36
  $this->log($post_data, $user_input);
37
  $links = $this->generate_links($downloads, $settings, $user_input);
38
- if (($settings['delivered_as'] == 'inline link') || ($settings['delivered_as'] == "both")) {
39
- if (isset($settings['force_download'])) {
40
- if (count($links) == 1) {
41
- foreach ($links as $link) {
42
- if(isset($settings['file'])){
43
- $linkURL= $settings['file'];
44
- }else{
45
- $linkURL = $this->link_url($link);
46
- }
47
-
48
- $additional_settings = $form_obj->prop('additional_settings');
49
- $additional_settings .= "\n" . "on_sent_ok: \"window.location.href = '$linkURL';\"";
50
- $form_obj->set_properties(array('additional_settings' => $additional_settings));
51
- }
52
-
53
- }
54
-
55
- } else {
56
- $form_obj = $this->inline_links($links, $form_obj,$settings);
57
- }
58
- }
59
 
60
  if (($settings['delivered_as'] == 'send email') || ($settings['delivered_as'] == 'both')) {
61
  $this->send_email($user_input, $links, $settings);
@@ -65,7 +44,6 @@ class Email_Before_Download_Process
65
  $form_obj->set_properties(array('mail' => $newMail));
66
  return $form_obj;
67
  }
68
-
69
  private function reply($mail,$links){
70
  $message = "The downloaded file name(s): ";
71
  foreach ($links as $link){
@@ -92,7 +70,6 @@ class Email_Before_Download_Process
92
  }
93
  return $new_array;
94
  }
95
-
96
  private function generate_email($body, $data, $links, $settings = null)
97
  {
98
  //build email to send to user
@@ -207,25 +184,22 @@ class Email_Before_Download_Process
207
  $linkCSS = get_option('email_before_download_link_css');
208
  $linkCSS = isset($linkCSS) ? $linkCSS : "";
209
  $target = $settings['link_format'];
210
- $html = "<span class=\"et-icon\"><span><a href=\"$downloadURL\" class=\"icon-button download-icon ebd_link $linkCSS\" target=\"$target\">";
211
  if(isset($link->title)){
212
  $html .= $link->title;
213
  }else {
214
  $html .= do_shortcode("[download_data id=\"$link->selected_id\" data=\"title\"]");
215
 
216
  }
217
- $html .= "</a></</span></span></br>";
218
  $linkHTML .= $html;
219
  }
220
  $linkHTML .= $htmlAfter. "</div>";
221
- if(version_compare(DEPENDENCY_MIN_VERSION, '5.0.0') < 0){
222
  $additional_settings = $form_obj->prop('additional_settings');
223
  $hideOnSubmit = "jQuery('.ebd_input').hide();jQuery('.cf7_input').hide(); ";
224
  $additional_settings .= "\n" . "on_sent_ok: \" jQuery('#$form_id').append('$linkHTML'); \"";
225
  $form_obj->set_properties(array('additional_settings' => $additional_settings));
226
- }else {
227
- set_transient( $form_id, $linkHTML);
228
- }
229
  return $form_obj;
230
  }
231
  private function email_links($links)
@@ -301,7 +275,13 @@ class Email_Before_Download_Process
301
 
302
  public function link_url($link)
303
  {
304
- return get_rest_url() . "ebd/file/$link->uid";
 
 
 
 
 
 
305
  }
306
 
307
  public function log($post_data, $user_data)
35
  }
36
  $this->log($post_data, $user_input);
37
  $links = $this->generate_links($downloads, $settings, $user_input);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  if (($settings['delivered_as'] == 'send email') || ($settings['delivered_as'] == 'both')) {
40
  $this->send_email($user_input, $links, $settings);
44
  $form_obj->set_properties(array('mail' => $newMail));
45
  return $form_obj;
46
  }
 
47
  private function reply($mail,$links){
48
  $message = "The downloaded file name(s): ";
49
  foreach ($links as $link){
70
  }
71
  return $new_array;
72
  }
 
73
  private function generate_email($body, $data, $links, $settings = null)
74
  {
75
  //build email to send to user
184
  $linkCSS = get_option('email_before_download_link_css');
185
  $linkCSS = isset($linkCSS) ? $linkCSS : "";
186
  $target = $settings['link_format'];
187
+ $html = "<a href=\"$downloadURL\" class=\"ebd_link $linkCSS\" target=\"$target\">";
188
  if(isset($link->title)){
189
  $html .= $link->title;
190
  }else {
191
  $html .= do_shortcode("[download_data id=\"$link->selected_id\" data=\"title\"]");
192
 
193
  }
194
+ $html .= "</a></br>";
195
  $linkHTML .= $html;
196
  }
197
  $linkHTML .= $htmlAfter. "</div>";
 
198
  $additional_settings = $form_obj->prop('additional_settings');
199
  $hideOnSubmit = "jQuery('.ebd_input').hide();jQuery('.cf7_input').hide(); ";
200
  $additional_settings .= "\n" . "on_sent_ok: \" jQuery('#$form_id').append('$linkHTML'); \"";
201
  $form_obj->set_properties(array('additional_settings' => $additional_settings));
202
+
 
 
203
  return $form_obj;
204
  }
205
  private function email_links($links)
275
 
276
  public function link_url($link)
277
  {
278
+ $permalink = get_option('permalink_structure');
279
+ if($permalink != ""){
280
+ $spacer = "?uid=";
281
+ }else{
282
+ $spacer = "&uid=";
283
+ }
284
+ return do_shortcode("[download_data id=\"$link->selected_id\" data=\"download_link\"]").$spacer.$link->uid;
285
  }
286
 
287
  public function log($post_data, $user_data)
includes/class-email-before-download-shortcode.php CHANGED
@@ -22,7 +22,14 @@ class Email_Before_Download_Shortcode {
22
  }
23
  public function init_shortcode($user_atts = array(), $content = null, $tag = 'email-download')
24
  {
 
 
 
25
  $user_atts = array_change_key_case((array)$user_atts, CASE_LOWER);
 
 
 
 
26
  if(isset($user_atts['checked'])){
27
  if($user_atts['checked'] == 'no'){
28
  $user_atts['checked'] = '';
22
  }
23
  public function init_shortcode($user_atts = array(), $content = null, $tag = 'email-download')
24
  {
25
+ if(isset($user_atts['title']))
26
+ $tmpTitle = $user_atts['title'];
27
+
28
  $user_atts = array_change_key_case((array)$user_atts, CASE_LOWER);
29
+
30
+ if(isset($tmpTitle))
31
+ $user_atts['title'] = $tmpTitle;
32
+
33
  if(isset($user_atts['checked'])){
34
  if($user_atts['checked'] == 'no'){
35
  $user_atts['checked'] = '';
includes/class-email-before-download.php CHANGED
@@ -30,7 +30,6 @@ class Email_Before_Download {
30
  $this->define_process_hooks();
31
  $this->define_downloader_hooks();
32
  $this->build_shortcode();
33
- $this->api();
34
 
35
 
36
  }
@@ -65,7 +64,6 @@ class Email_Before_Download {
65
  $this->loader->add_action( 'admin_init', $plugin_admin, 'register_settings' );
66
  $this->loader->add_action( 'admin_post_ebd.csv',$plugin_admin, 'print_csv' );
67
  $this->loader->add_action( 'admin_post_ebd.purge',$plugin_admin, 'purge_data' );
68
- $this->loader->add_action('upgrader_process_complete', $plugin_admin, 'flush_api');
69
 
70
 
71
  }
@@ -77,11 +75,10 @@ class Email_Before_Download {
77
  $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
78
  $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
79
  $this->loader->add_filter( 'the_content', $plugin_public,'shortcode_cleanup');
80
- $this->loader->add_filter( 'init', $plugin_public,'session_start');
81
- if(version_compare(DEPENDENCY_MIN_VERSION, '5.0.0') >= 0) {
82
  $this->loader->add_action('wp_ajax_ebd_inline_links', $plugin_public, 'ebd_ajax');
83
  $this->loader->add_action('wp_ajax_nopriv_ebd_inline_links', $plugin_public, 'ebd_ajax');
84
- }
 
85
  }
86
  private function define_process_hooks(){
87
  $plugin_process = new Email_Before_Download_Process( $this->get_plugin_name(), $this->get_version() );
@@ -116,21 +113,11 @@ class Email_Before_Download {
116
  return $this->version;
117
  }
118
 
119
- public function api(){
120
- add_action( 'rest_api_init', function () {
121
- register_rest_route( 'ebd/file/', '(?P<uid>[a-zA-Z0-9-]+)', array(
122
- 'methods' => 'GET',
123
- 'callback' => array($this,'run_download')
124
- ,
125
- ) );
126
- } );
127
-
128
-
129
- }
130
  public function run_download($data) {
131
  $downloader = new Email_Before_download_Downloader( $this->get_plugin_name(), $this->get_version() );
132
  $downloader->serve_file($data['uid']);
133
- return ;
 
134
  }
135
 
136
  }
30
  $this->define_process_hooks();
31
  $this->define_downloader_hooks();
32
  $this->build_shortcode();
 
33
 
34
 
35
  }
64
  $this->loader->add_action( 'admin_init', $plugin_admin, 'register_settings' );
65
  $this->loader->add_action( 'admin_post_ebd.csv',$plugin_admin, 'print_csv' );
66
  $this->loader->add_action( 'admin_post_ebd.purge',$plugin_admin, 'purge_data' );
 
67
 
68
 
69
  }
75
  $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
76
  $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
77
  $this->loader->add_filter( 'the_content', $plugin_public,'shortcode_cleanup');
 
 
78
  $this->loader->add_action('wp_ajax_ebd_inline_links', $plugin_public, 'ebd_ajax');
79
  $this->loader->add_action('wp_ajax_nopriv_ebd_inline_links', $plugin_public, 'ebd_ajax');
80
+ $this->loader->add_filter('dlm_can_download', $plugin_public, 'record',10,2);
81
+
82
  }
83
  private function define_process_hooks(){
84
  $plugin_process = new Email_Before_Download_Process( $this->get_plugin_name(), $this->get_version() );
113
  return $this->version;
114
  }
115
 
 
 
 
 
 
 
 
 
 
 
 
116
  public function run_download($data) {
117
  $downloader = new Email_Before_download_Downloader( $this->get_plugin_name(), $this->get_version() );
118
  $downloader->serve_file($data['uid']);
119
+ exit();
120
+
121
  }
122
 
123
  }
public/class-email-before-download-public.php CHANGED
@@ -32,10 +32,8 @@ class Email_Before_Download_Public
32
 
33
  public function enqueue_scripts()
34
  {
35
- if(version_compare(DEPENDENCY_MIN_VERSION, '5.0.0') >= 0) {
36
  wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/email-before-download-public.js', array('jquery'), $this->version, true);
37
  wp_localize_script($this->plugin_name, 'ebd_inline', array('ajaxurl' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce('ebd'),));
38
- }
39
  }
40
  public function shortcode_cleanup($content)
41
  {
@@ -59,19 +57,86 @@ class Email_Before_Download_Public
59
 
60
  public function ebd_ajax(){
61
  check_ajax_referer( 'ebd', 'security');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- $id = $_POST['id'];
64
- $links = get_transient( $id );
65
- delete_transient( $id );
 
 
66
  if(isset($links)){
67
- echo $links;
68
  }else{
69
- echo 'no data found';
70
  }
 
71
  exit();
72
  }
73
- public function session_start() {
74
- if( !session_id() )
75
- session_start();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
  }
32
 
33
  public function enqueue_scripts()
34
  {
 
35
  wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/email-before-download-public.js', array('jquery'), $this->version, true);
36
  wp_localize_script($this->plugin_name, 'ebd_inline', array('ajaxurl' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce('ebd'),));
 
37
  }
38
  public function shortcode_cleanup($content)
39
  {
57
 
58
  public function ebd_ajax(){
59
  check_ajax_referer( 'ebd', 'security');
60
+ $permalink = get_option('permalink_structure');
61
+ if($permalink != ""){
62
+ $spacer = "?uid=";
63
+ }else{
64
+ $spacer = "&uid=";
65
+
66
+ }
67
+ $postData = sanitize_post($_POST);
68
+ $data = array();
69
+ $htmlBefore = get_option('email_before_download_html_before');
70
+ $htmlAfter = get_option('email_before_download_html_after');
71
+ $linkCSS = get_option('email_before_download_link_css');
72
+ $db = new Email_Before_Download_DB();
73
+ $links = array();
74
+ $linksHTML = "";
75
+ foreach ($postData['downloads'] as $download){
76
+ $tmp = explode('|', $download);
77
+ $links[$tmp[0]]['title'] = $tmp[1];
78
+ }
79
+ foreach ($postData['settings'] as $item){
80
+ $tmp = explode('|',$item);
81
+ $settings[$tmp[0]] = $tmp[1];
82
+ }
83
+ if(strtolower($settings['delivered_as']) == 'send email') {
84
+ echo json_encode('email sent');
85
+ exit();
86
+ }
87
+ $DBLinks = $db->get_ajax_links($postData['email']);
88
+ if((count($DBLinks) == 1 ) && ( isset($settings['force_download']) ) ){
89
+ $data['download'] = 'yes';
90
+ $data['url'] = do_shortcode("[download_data id=\"".$DBLinks[0]->selected_id."\" data=\"download_link\"]").$spacer.$DBLinks[0]->uid;
91
+ echo json_encode($data);
92
+ exit();
93
+ }
94
 
95
+ foreach ($DBLinks as $link){
96
+
97
+ $shortCode = do_shortcode("[download_data id=\"$link->selected_id\" data=\"download_link\"]").$spacer.$link->uid;
98
+ $linksHTML .= "<a class=\"ebd_link $linkCSS\" href=\"".$shortCode."\" target=\"" .$settings['link_format']. "\" >".$links[$link->selected_id]['title']."</a></br>" ;
99
+ }
100
  if(isset($links)){
101
+ $data['html'] = "<div class=\"ebd_results\">".$htmlBefore.$linksHTML.$htmlAfter."</div>";
102
  }else{
103
+ $data['error'] = 'no data found';
104
  }
105
+ echo json_encode($data);
106
  exit();
107
  }
108
+ public function record($allowed, $download){
109
+ $permalink = get_option('permalink_structure');
110
+ if($permalink != ""){
111
+ $downloadID = $download->post->ID;
112
+ }else {
113
+ $downloadID = $_GET['download'];
114
+
115
+ }
116
+ $db = new Email_Before_Download_DB();
117
+
118
+ $inEBD = $db->skip_check($downloadID);
119
+ if($inEBD){
120
+ if(!isset($_GET['uid']))
121
+ wp_die(__('No direct access. Please fill out a new form to generate a new link.', 'email-before-download'));
122
+
123
+ $link = $db->select_link('uid', $_GET['uid']);
124
+
125
+ if(!$link)
126
+ wp_die(__('Invalid UID Please fill out a new form to generate a new link.', 'email-before-download'));
127
+
128
+ if ($this->expired($link))
129
+ wp_die(__('This download has expired. Please fill out a new form to generate a new link.', 'email-before-download'));
130
+
131
+ $db->mark_downloaded($link->id);
132
+ }
133
+
134
+ return $allowed;
135
+ }
136
+ public function expired($link)
137
+ {
138
+ if ($link->expire_time)
139
+ if ($link->expire_time < time()) return true;
140
+ return false;
141
  }
142
  }
public/js/email-before-download-public.js CHANGED
@@ -1,13 +1,35 @@
1
  jQuery( document ).ready(function() {
2
  document.addEventListener('wpcf7mailsent', function (event) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  var id = event.detail.id;
4
  var data = {
5
  action: 'ebd_inline_links',
6
- id: id,
 
 
7
  security: ebd_inline.ajax_nonce
8
  };
9
  jQuery.post(ebd_inline.ajaxurl, data, function (data) {
10
- jQuery('#' + id).append(data);
 
 
 
 
 
 
11
  }
12
  );
13
  }, false);
1
  jQuery( document ).ready(function() {
2
  document.addEventListener('wpcf7mailsent', function (event) {
3
+ var inputs = event.detail.inputs;
4
+ var downloads = [];
5
+ var settings = [];
6
+ for ( var i = 0; i < inputs.length; i++ ) {
7
+ if ( 'your-email' === inputs[i].name ) {
8
+ var email = inputs[i].value ;
9
+ }
10
+ if("ebd_downloads[]" === inputs[i].name){
11
+ downloads.push(inputs[i].value);
12
+ }
13
+ if('ebd_settings[]' === inputs[i].name){
14
+ settings.push(inputs[i].value);
15
+ }
16
+ }
17
  var id = event.detail.id;
18
  var data = {
19
  action: 'ebd_inline_links',
20
+ email: email,
21
+ downloads: downloads,
22
+ settings: settings,
23
  security: ebd_inline.ajax_nonce
24
  };
25
  jQuery.post(ebd_inline.ajaxurl, data, function (data) {
26
+ data = JSON.parse(data);
27
+ if(data.download){
28
+ window.location.href = data.url;
29
+ }else{
30
+ jQuery('#' + id).append(data.html);
31
+ }
32
+
33
  }
34
  );
35
  }, false);
readme.txt CHANGED
@@ -106,6 +106,11 @@ This is the list of all short code attributes that can be used. Some of them o
106
 
107
 
108
  == Changelog ==
 
 
 
 
 
109
 
110
  =5.1.1=
111
  * Fixed issue where some instances wouldn't activate after update
106
 
107
 
108
  == Changelog ==
109
+ =5.1.2=
110
+ * Simplified use of PHPDomDocument to better function with older versions of PHP
111
+ * Let Javascript do more of the work for hiding/showing forms
112
+ * Removed custom API endpoint that was giving issue for some users
113
+ * Using Download Monitor hook to serve files
114
 
115
  =5.1.1=
116
  * Fixed issue where some instances wouldn't activate after update