Simple Download Monitor - Version 2.9

Version Description

  • Added visitor Country to database table; allowing tracking of each download visitors Country.
  • Visitor Country is also seen in the "Logs" page; can be sorted; and exported.
Download this release

Release Info

Developer mra13
Plugin Icon 128x128 Simple Download Monitor
Version 2.9
Comparing to
See all releases

Code changes from version 2.5 to 2.9

css/images/Thumbs.db CHANGED
Binary file
css/sdm_wp_styles.css CHANGED
@@ -261,4 +261,10 @@
261
  -webkit-box-shadow: 0 1px 1px #ebebeb, inset 0 1px 0 #f3f3f3;
262
  -moz-box-shadow: 0 1px 1px #ebebeb, inset 0 1px 0 #f3f3f3;
263
  box-shadow: 0 1px 1px #ebebeb, inset 0 1px 0 #f3f3f3;
 
 
 
 
 
 
264
  }
261
  -webkit-box-shadow: 0 1px 1px #ebebeb, inset 0 1px 0 #f3f3f3;
262
  -moz-box-shadow: 0 1px 1px #ebebeb, inset 0 1px 0 #f3f3f3;
263
  box-shadow: 0 1px 1px #ebebeb, inset 0 1px 0 #f3f3f3;
264
+ }
265
+
266
+ /* Ajax category file browser shortcode */
267
+ .sdm_object_tree .sdm_post_title{
268
+ margin-right: 5px;
269
+ display: block;
270
  }
js/sdm_admin_scripts.js CHANGED
@@ -41,10 +41,10 @@ jQuery(document).ready(function($){
41
  if(response) { // ** If response was successful
42
  $('#sdm_thumbnail_image').remove();
43
  $('#sdm_upload_thumbnail').val('');
44
- alert('Image Successfully Removed');
45
  }
46
  else { // ** Else response was unsuccessful
47
- alert('Error with AJAX');
48
  }
49
  }
50
  );
41
  if(response) { // ** If response was successful
42
  $('#sdm_thumbnail_image').remove();
43
  $('#sdm_upload_thumbnail').val('');
44
+ alert(sdm_translations.image_removed);
45
  }
46
  else { // ** Else response was unsuccessful
47
+ alert(sdm_translations.ajax_error);
48
  }
49
  }
50
  );
js/sdm_wp_scripts.js CHANGED
@@ -2,6 +2,53 @@
2
 
3
  jQuery(document).ready(function($) {
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  $('.pass_sumbit').click(function() {
7
 
@@ -21,7 +68,7 @@ jQuery(document).ready(function($) {
21
 
22
  if(response.success === 'no') { // If the password match failed
23
 
24
- alert('Incorrect Password');
25
  $('.pass_text').val(''); // Clear password field
26
  }
27
 
2
 
3
  jQuery(document).ready(function($) {
4
 
5
+ // Populate all nested titles and links
6
+ $('li.sdm_cat').each(function() {
7
+
8
+ var $this = $(this);
9
+ this_slug = $this.attr('id');
10
+ this_id = $this.children('.sdm_cat_title').attr('id');
11
+
12
+ // Run ajax
13
+ $.post(
14
+ sdm_ajax_script.ajaxurl,
15
+ {
16
+ action: 'sdm_pop_cats',
17
+ cat_slug: this_slug,
18
+ parent_id: this_id
19
+ },
20
+ function (response) {
21
+
22
+ // Loop array returned from ajax function
23
+ $.each(response.final_array, function(key, value) {
24
+
25
+ // Populate each matched post title and permalink
26
+ $this.children('.sdm_placeholder').append('<a href="'+value['permalink']+'"><span class="sdm_post_title" style="cursor:pointer;">'+value['title']+'</span></a>');
27
+ });
28
+ }
29
+ );
30
+ });
31
+
32
+ // Hide results on page load
33
+ $('li.sdm_cat').children('.sdm_placeholder').hide();
34
+ //$('li.sdm_cat').children('ul').hide();
35
+ //$('.sdm_cat ul').children().hide();
36
+ $('.sdm_cat ul').css('display', 'none');
37
+
38
+ // Slide toggle for each list item
39
+ $('body').on('click', '.sdm_cat_title', function(e) {
40
+
41
+ // If there is any html.. then we have more elements
42
+ if($(this).next().html() != '') {
43
+
44
+ e.stopPropagation(); // prevetn climbing dom tree
45
+ $(this).next().slideToggle(); // toggle div titles
46
+ $(this).next().next().slideToggle(); // toggle next elements
47
+ $(this).next().next().find('ul').slideToggle(); // toggle all child ul elements
48
+ }
49
+ });
50
+
51
+
52
 
53
  $('.pass_sumbit').click(function() {
54
 
68
 
69
  if(response.success === 'no') { // If the password match failed
70
 
71
+ alert(sdm_frontend_translations.incorrect_password);
72
  $('.pass_text').val(''); // Clear password field
73
  }
74
 
langs/sdm_lang-de_DE.mo ADDED
Binary file
langs/sdm_lang-de_DE.po ADDED
@@ -0,0 +1,611 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Simple Download Monitor v2.6\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: 2014-03-24 05:18:24+0000\n"
7
+ "Last-Translator: freizeittreff-bielefeld <freizeittreff.bielefeld@gmail.com>\n"
8
+ "Language-Team: \n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
13
+ "X-Generator: CSL v1.x\n"
14
+ "X-Poedit-Language: German\n"
15
+ "X-Poedit-Country: GERMANY\n"
16
+ "X-Poedit-SourceCharset: utf-8\n"
17
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
18
+ "X-Poedit-Basepath: ../\n"
19
+ "X-Poedit-Bookmarks: \n"
20
+ "X-Poedit-SearchPath-0: .\n"
21
+ "X-Textdomain-Support: yes"
22
+
23
+ #: main.php:71
24
+ #: main.php:291
25
+ #@ sdm_lang
26
+ msgid "Settings"
27
+ msgstr "Einstellungen"
28
+
29
+ #: main.php:163
30
+ #: main.php:164
31
+ #: main.php:169
32
+ #: main.php:175
33
+ #: main.php:567
34
+ #: main.php:968
35
+ #: sdm-shortcodes.php:92
36
+ #@ sdm_lang
37
+ msgid "Downloads"
38
+ msgstr "Downloads"
39
+
40
+ #: main.php:165
41
+ #: main.php:166
42
+ #@ sdm_lang
43
+ msgid "Add New"
44
+ msgstr "Neuen Download hinzufügen"
45
+
46
+ #: main.php:167
47
+ #@ sdm_lang
48
+ msgid "Edit Download"
49
+ msgstr "Download bearbeiten"
50
+
51
+ #: main.php:168
52
+ #@ sdm_lang
53
+ msgid "New Download"
54
+ msgstr "Neuer Download"
55
+
56
+ #: main.php:170
57
+ #@ sdm_lang
58
+ msgid "View Download"
59
+ msgstr "Download anzeigen"
60
+
61
+ #: main.php:171
62
+ #@ sdm_lang
63
+ msgid "Search Downloads"
64
+ msgstr "Download suchen"
65
+
66
+ #: main.php:172
67
+ #@ sdm_lang
68
+ msgid "No Downloads found"
69
+ msgstr "Keine Downloads gefunden"
70
+
71
+ #: main.php:173
72
+ #@ sdm_lang
73
+ msgid "No Downloads found in Trash"
74
+ msgstr "Keine Downloads im Papierkorb gefunden"
75
+
76
+ #: main.php:199
77
+ #@ default
78
+ msgctxt "sdm_lang"
79
+ msgid "Categories"
80
+ msgstr "Kategorien"
81
+
82
+ #: main.php:200
83
+ #@ default
84
+ msgctxt "sdm_lang"
85
+ msgid "Category"
86
+ msgstr "Kategorie"
87
+
88
+ #: main.php:201
89
+ #@ sdm_lang
90
+ msgid "Search Categories"
91
+ msgstr "Kategorien durchsuchen"
92
+
93
+ #: main.php:202
94
+ #@ sdm_lang
95
+ msgid "All Categories"
96
+ msgstr "Alle Kategorien"
97
+
98
+ #: main.php:203
99
+ #@ sdm_lang
100
+ msgid "Categories Genre"
101
+ msgstr "Kategorie Gattung"
102
+
103
+ #: main.php:204
104
+ #@ sdm_lang
105
+ msgid "Categories Genre:"
106
+ msgstr "Kategorie Gattung:"
107
+
108
+ #: main.php:205
109
+ #@ sdm_lang
110
+ msgid "Edit Category"
111
+ msgstr "Kategorie bearbeiten"
112
+
113
+ #: main.php:206
114
+ #@ sdm_lang
115
+ msgid "Update Category"
116
+ msgstr "Kategorie aktualisieren"
117
+
118
+ #: main.php:207
119
+ #@ sdm_lang
120
+ msgid "Add New Category"
121
+ msgstr "Neue Kategorie hinzufügen"
122
+
123
+ #: main.php:208
124
+ #@ sdm_lang
125
+ msgid "New Category"
126
+ msgstr "Neue Kategorie"
127
+
128
+ #: main.php:209
129
+ #: main.php:966
130
+ #@ sdm_lang
131
+ msgid "Categories"
132
+ msgstr "Kategorien"
133
+
134
+ #: main.php:224
135
+ #@ default
136
+ msgctxt "sdm_lang"
137
+ msgid "Tags"
138
+ msgstr "Tags"
139
+
140
+ #: main.php:225
141
+ #@ default
142
+ msgctxt "sdm_lang"
143
+ msgid "Tag"
144
+ msgstr "Tag"
145
+
146
+ #: main.php:226
147
+ #@ sdm_lang
148
+ msgid "Search Tags"
149
+ msgstr "Tags suchen"
150
+
151
+ #: main.php:227
152
+ #@ sdm_lang
153
+ msgid "All Tags"
154
+ msgstr "Alle Tags"
155
+
156
+ #: main.php:228
157
+ #@ sdm_lang
158
+ msgid "Tags Genre"
159
+ msgstr "Tags Gattung"
160
+
161
+ #: main.php:229
162
+ #@ sdm_lang
163
+ msgid "Tags Genre:"
164
+ msgstr "Tags Gattung:"
165
+
166
+ #: main.php:230
167
+ #@ sdm_lang
168
+ msgid "Edit Tag"
169
+ msgstr "Tag bearbeiten"
170
+
171
+ #: main.php:231
172
+ #@ sdm_lang
173
+ msgid "Update Tag"
174
+ msgstr "Tag aktualisieren"
175
+
176
+ #: main.php:232
177
+ #@ sdm_lang
178
+ msgid "Add New Tag"
179
+ msgstr "Neuen Tag hinzufügen"
180
+
181
+ #: main.php:233
182
+ #@ sdm_lang
183
+ msgid "New Tag"
184
+ msgstr "Neuer Tag"
185
+
186
+ #: main.php:234
187
+ #: main.php:967
188
+ #@ sdm_lang
189
+ msgid "Tags"
190
+ msgstr "Tags"
191
+
192
+ #: main.php:290
193
+ #@ sdm_lang
194
+ msgid "Logs"
195
+ msgstr "Logs"
196
+
197
+ #: main.php:299
198
+ #@ sdm_lang
199
+ msgid "Simple Download Monitor Settings Page"
200
+ msgstr "Simple Donwload Monitor Einstellungs-Seite"
201
+
202
+ #: main.php:311
203
+ #: main.php:509
204
+ #@ sdm_lang
205
+ msgid "Admin Options"
206
+ msgstr "Optionen"
207
+
208
+ #: main.php:314
209
+ #@ sdm_lang
210
+ msgid "Control various plugin features."
211
+ msgstr "Verschiedene Plugin-Eigenschaften kontrollieren"
212
+
213
+ #: main.php:331
214
+ #@ sdm_lang
215
+ msgid "Color Options"
216
+ msgstr "Farben"
217
+
218
+ #: main.php:334
219
+ #@ sdm_lang
220
+ msgid "Adjust color options"
221
+ msgstr "Farbe anpassen"
222
+
223
+ #: main.php:366
224
+ #@ sdm_lang
225
+ msgid "Description"
226
+ msgstr "Beschreibung"
227
+
228
+ #: main.php:371
229
+ #@ sdm_lang
230
+ msgid "Upload File"
231
+ msgstr "Datei hochladen"
232
+
233
+ #: main.php:376
234
+ #@ sdm_lang
235
+ msgid "File Thumbnail (Optional)"
236
+ msgstr "Datei Thumbnail (optional)"
237
+
238
+ #: main.php:381
239
+ #@ sdm_lang
240
+ msgid "Shortcodes"
241
+ msgstr "Shortcodes"
242
+
243
+ #: main.php:386
244
+ #@ sdm_lang
245
+ msgid "Statistics"
246
+ msgstr "Statistiken"
247
+
248
+ #: main.php:394
249
+ #@ sdm_lang
250
+ msgid "Add a description for this download item."
251
+ msgstr "Füge eine Beschreibung für diesen Download hinzu ..."
252
+
253
+ #: main.php:408
254
+ #@ sdm_lang
255
+ msgid "Click \"Select File\" to upload (or choose) the file."
256
+ msgstr "Klicke \"Datei auswählen\" zum Upload der Datei oder gib den Verzeichnisort direkt ein."
257
+
258
+ #: main.php:413
259
+ #@ sdm_lang
260
+ msgid "File URL:"
261
+ msgstr "Datei URL:"
262
+
263
+ #: main.php:422
264
+ #@ sdm_lang
265
+ msgid "Click \"Select Image\" to upload (or choose) the file thumbnail image. This thumbnail image will be used to create a fancy file download box if you want to use it."
266
+ msgstr "Klicke \"Image auswählen\" um eine Datei hochzuladen oder wähle ein vorhandenes Bild aus der Mediathek. Der Thumbnail wird genutzt, um eine \"Fancy-Datei-Download-Box\" zu erzeugen (optional)."
267
+
268
+ #: main.php:424
269
+ #@ sdm_lang
270
+ msgid "Recommended image size is 75px by 75px."
271
+ msgstr "Empfohlene Image-Größe: 75px x 75px"
272
+
273
+ #: main.php:427
274
+ #@ sdm_lang
275
+ msgid "Select Image"
276
+ msgstr "Image auswählen"
277
+
278
+ #: main.php:428
279
+ #@ sdm_lang
280
+ msgid "Remove Image"
281
+ msgstr "Image entfernen"
282
+
283
+ #: main.php:443
284
+ #@ sdm_lang
285
+ msgid "This is the shortcode which can used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter to add this shortcode to a post or page."
286
+ msgstr "<b>Shortcode zum Einfügen des Downloads in einen Beitrag oder eine Seite (inklusive Download Button). <br/>Alternativ ist die direkte Eingabe über den Shortcode-Button im WP-Editor möglich.</b> <br/>"
287
+
288
+ #: main.php:448
289
+ #@ sdm_lang
290
+ msgid "This shortcode may be used as a download counter."
291
+ msgstr "<b>Shortcode zum Einfügen des Download-Zählers.</b><br/>"
292
+
293
+ #: main.php:455
294
+ #@ sdm_lang
295
+ msgid "These are the statistics for this download item."
296
+ msgstr "Statistiken für den jeweiligen Download."
297
+
298
+ #: main.php:460
299
+ #@ sdm_lang
300
+ msgid "Number of Downloads:"
301
+ msgstr "Anzahl der Downloads:"
302
+
303
+ #: main.php:510
304
+ #@ sdm_lang
305
+ msgid "Colors"
306
+ msgstr "Farben"
307
+
308
+ #: main.php:512
309
+ #@ sdm_lang
310
+ msgid "Remove Tinymce Button"
311
+ msgstr "Tinymce Button entfernen"
312
+
313
+ #: main.php:513
314
+ #@ sdm_lang
315
+ msgid "Download Button Color"
316
+ msgstr "Download Button Farbe"
317
+
318
+ #: main.php:516
319
+ #@ sdm_lang
320
+ msgid "Admin options settings"
321
+ msgstr "Einstellungen: Admin Optionen"
322
+
323
+ #: main.php:519
324
+ #@ sdm_lang
325
+ msgid "Front End colors settings"
326
+ msgstr "Front-End Farb-Einstellungen"
327
+
328
+ #: main.php:524
329
+ #@ sdm_lang
330
+ msgid "Removes the SDM Downloads button from the WP content editor."
331
+ msgstr "Entferne den SDM-Download-Shortcode-Button vom WP-Editor."
332
+
333
+ #: main.php:529
334
+ #@ sdm_lang
335
+ msgid "Green"
336
+ msgstr "Grün"
337
+
338
+ #: main.php:529
339
+ #@ sdm_lang
340
+ msgid "Blue"
341
+ msgstr "Blau"
342
+
343
+ #: main.php:529
344
+ #@ sdm_lang
345
+ msgid "Purple"
346
+ msgstr "Lila"
347
+
348
+ #: main.php:529
349
+ #@ sdm_lang
350
+ msgid "Teal"
351
+ msgstr "Blaugrün"
352
+
353
+ #: main.php:529
354
+ #@ sdm_lang
355
+ msgid "Dark Blue"
356
+ msgstr "Dunkelblau"
357
+
358
+ #: main.php:529
359
+ #@ sdm_lang
360
+ msgid "Black"
361
+ msgstr "Schwarz"
362
+
363
+ #: main.php:529
364
+ #@ sdm_lang
365
+ msgid "Grey"
366
+ msgstr "Grau"
367
+
368
+ #: main.php:529
369
+ #@ sdm_lang
370
+ msgid "Pink"
371
+ msgstr "Rosa"
372
+
373
+ #: main.php:529
374
+ #@ sdm_lang
375
+ msgid "Orange"
376
+ msgstr "Orange"
377
+
378
+ #: main.php:529
379
+ #@ sdm_lang
380
+ msgid "White"
381
+ msgstr "Weiß"
382
+
383
+ #: main.php:538
384
+ #@ sdm_lang
385
+ msgid "Adjusts the color of the \"Download Now\" button."
386
+ msgstr "Farbe des Buttons <b> \"Jetzt herunterladen ...\" </b> anpassen."
387
+
388
+ #: main.php:614
389
+ #: main.php:963
390
+ #@ sdm_lang
391
+ msgid "Title"
392
+ msgstr "Titel"
393
+
394
+ #: main.php:615
395
+ #: main.php:965
396
+ #@ sdm_lang
397
+ msgid "File"
398
+ msgstr "Datei"
399
+
400
+ #: main.php:616
401
+ #@ sdm_lang
402
+ msgid "Visitor IP"
403
+ msgstr "Besucher IP"
404
+
405
+ #: main.php:617
406
+ #@ sdm_lang
407
+ msgid "Date"
408
+ msgstr "Datum"
409
+
410
+ #: main.php:636
411
+ #@ sdm_lang
412
+ msgid "Delete Permanently"
413
+ msgstr "Endgültig löschen"
414
+
415
+ #: main.php:637
416
+ #@ sdm_lang
417
+ msgid "Export All as Excel"
418
+ msgstr "Als EXCEL-Datei exportieren"
419
+
420
+ #: main.php:765
421
+ #@ sdm_lang
422
+ msgid "Download Logs"
423
+ msgstr "Download Logs"
424
+
425
+ #: main.php:768
426
+ #@ sdm_lang
427
+ msgid "This page lists all tracked downloads."
428
+ msgstr "Diese Seite listet alle erfassten Donwloads"
429
+
430
+ #: main.php:789
431
+ #@ sdm_lang
432
+ msgid "Enter Password to Download:"
433
+ msgstr "Bitte gib das Passwort ein ..."
434
+
435
+ #: main.php:792
436
+ #@ sdm_lang
437
+ msgid "Submit"
438
+ msgstr "Absenden"
439
+
440
+ #: main.php:962
441
+ #@ sdm_lang
442
+ msgid "Image"
443
+ msgstr "Image"
444
+
445
+ #: main.php:964
446
+ #@ sdm_lang
447
+ msgid "ID"
448
+ msgstr "ID"
449
+
450
+ #: main.php:969
451
+ #@ sdm_lang
452
+ msgid "Date Posted"
453
+ msgstr "Datum"
454
+
455
+ #: sdm-shortcodes.php:46
456
+ #: sdm-shortcodes.php:156
457
+ #@ sdm_lang
458
+ msgid "green"
459
+ msgstr "grün"
460
+
461
+ #: sdm-shortcodes.php:51
462
+ #: sdm-shortcodes.php:178
463
+ #@ sdm_lang
464
+ msgid "Download Now!"
465
+ msgstr "Jetzt herunterladen ..."
466
+
467
+ #: main.php:125
468
+ #@ sdm_lang
469
+ msgid "Image Successfully Removed"
470
+ msgstr "Image erfolgreich entfernt"
471
+
472
+ #: main.php:126
473
+ #@ sdm_lang
474
+ msgid "Error with AJAX"
475
+ msgstr "AJAX Fehler"
476
+
477
+ #: main.php:136
478
+ #@ sdm_lang
479
+ msgid "Please select a Download Item:"
480
+ msgstr "Bitte Download auswählen:"
481
+
482
+ #: main.php:136
483
+ #@ sdm_lang
484
+ msgid "Download Title"
485
+ msgstr "Titel"
486
+
487
+ #: main.php:136
488
+ #@ sdm_lang
489
+ msgid "Include Fancy Box"
490
+ msgstr "Beinhaltet Fancy Box"
491
+
492
+ #: main.php:136
493
+ #@ sdm_lang
494
+ msgid "Insert SDM Shortcode"
495
+ msgstr "SDM Shortcode einfügen"
496
+
497
+ #: main.php:146
498
+ #@ sdm_lang
499
+ msgid "Incorrect Password"
500
+ msgstr "Falsches Passwort !!"
501
+
502
+ #: main.php:302
503
+ #@ sdm_lang
504
+ msgid "Follow us"
505
+ msgstr "Folge uns"
506
+
507
+ #: main.php:302
508
+ #@ sdm_lang
509
+ msgid "on Twitter, Google+ or via Email to stay upto date about the new features of this plugin."
510
+ msgstr "auf Twitter, Google+ oder via Email um über neue Features des Plugins auf dem Laufenden zu bleiben."
511
+
512
+ #: main.php:352
513
+ #@ sdm_lang
514
+ msgid "If you need a feature rich and supported plugin for selling your digital items then checkout our"
515
+ msgstr "Wenn Sie ein funktionsreiches Plugin zum Verkauf Ihrer <b>digitalen Produkte</b> benötigen, dann testen Sie unser Plugin. Wir garantieren Ihnen gleichzeitig umfassenden technische Support."
516
+
517
+ #: main.php:352
518
+ #@ sdm_lang
519
+ msgid "WP eStore Plugin"
520
+ msgstr "WP eStore Plugin"
521
+
522
+ #: main.php:411
523
+ #@ sdm_lang
524
+ msgid "Select File"
525
+ msgstr "Datei auswählen"
526
+
527
+ #: main.php:566
528
+ #@ sdm_lang
529
+ msgid "Download"
530
+ msgstr "Download"
531
+
532
+ #: main.php:589
533
+ #@ sdm_lang
534
+ msgid "Edit"
535
+ msgstr "Bearbeiten"
536
+
537
+ #: main.php:590
538
+ #@ sdm_lang
539
+ msgid "Delete"
540
+ msgstr "Löschen"
541
+
542
+ #: main.php:652
543
+ #@ sdm_lang
544
+ msgid "Nope! Security check failed!"
545
+ msgstr "Nö! Sicherheitsprüfung nicht bestanden!"
546
+
547
+ #: main.php:661
548
+ #@ sdm_lang
549
+ msgid "Download Export File"
550
+ msgstr "Download Export-Datei"
551
+
552
+ #: main.php:668
553
+ #@ sdm_lang
554
+ msgid "No entries were selected."
555
+ msgstr "Keine Einträge ausgewählt."
556
+
557
+ #: main.php:668
558
+ #: main.php:684
559
+ #: main.php:687
560
+ #: main.php:704
561
+ #: main.php:707
562
+ #@ sdm_lang
563
+ msgid "Click to Dismiss"
564
+ msgstr "Ausblenden"
565
+
566
+ #: main.php:684
567
+ #@ sdm_lang
568
+ msgid "Entries Deleted!"
569
+ msgstr "Einträge gelöscht!"
570
+
571
+ #: main.php:687
572
+ #: main.php:707
573
+ #@ sdm_lang
574
+ msgid "Error"
575
+ msgstr "Fehler"
576
+
577
+ #: main.php:704
578
+ #@ sdm_lang
579
+ msgid "Entry Deleted!"
580
+ msgstr "Eintrag gelöscht!"
581
+
582
+ #: main.php:838
583
+ #@ sdm_lang
584
+ msgid "Error! Failed to log the download request in the database table"
585
+ msgstr "Fehler! Eintrag der Download-Anfrage in die Datenbank gescheitert!"
586
+
587
+ #: main.php:848
588
+ #@ sdm_lang
589
+ msgid "Error! The URL value is empty. Please specify a correct URL value to redirect to!"
590
+ msgstr "Fehler! Der URL-Wert ist leer. Bitte geben Sie eine korrekte URL ein!"
591
+
592
+ #: sdm-shortcodes.php:110
593
+ #@ sdm_lang
594
+ msgid "Error! You must enter a category slug OR a category id with this shortcode. Refer to the documentation for usage instructions."
595
+ msgstr "Fehler! Sie müssen bei einem Shortcode entweder einen Kategorie-Slug (bereinigter Namenskürzel der URL) <b>ODER</b> eine Kategorie-ID eingeben. Bitte beachten Sie die Dokumentation für detaillierte Informationen."
596
+
597
+ #: sdm-shortcodes.php:114
598
+ #@ sdm_lang
599
+ msgid "Error! Please enter a category slug OR id; not both."
600
+ msgstr "Fehler! Bitte geben Sie entweder einen Kategorie-Slug ODER die ID ein; nicht beides."
601
+
602
+ #: sdm-shortcodes.php:144
603
+ #@ sdm_lang
604
+ msgid "There are no download items matching this category criteria."
605
+ msgstr "Es existieren keine Downloads, die den Kategorie-Kriterien entsprechen."
606
+
607
+ #: main.php:532
608
+ #@ sdm_lang
609
+ msgid "current"
610
+ msgstr "aktiv"
611
+
main.php CHANGED
@@ -3,1102 +3,1156 @@
3
  * Plugin Name: Simple Download Monitor
4
  * Plugin URI: http://www.tipsandtricks-hq.com/development-center
5
  * Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
6
- * Version: 2.5
7
  * Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
8
  * Author URI: http://www.tipsandtricks-hq.com/development-center
9
  * License: GPL2
10
  */
11
-
12
  define('WP_SIMPLE_DL_MONITOR_DIR_NAME', dirname(plugin_basename(__FILE__)));
13
- define('WP_SIMPLE_DL_MONITOR_URL', plugins_url('',__FILE__));
14
- define('WP_SIMPLE_DL_MONITOR_PATH',plugin_dir_path( __FILE__ ));
15
 
16
  global $sdm_db_version;
17
- $sdm_db_version = '2.5';
 
 
 
 
 
 
 
18
 
19
- register_activation_hook(__FILE__, 'sdm_install_db_table' );
20
  function sdm_install_db_table() {
21
-
22
- global $wpdb;
23
- global $sdm_db_version;
24
-
25
- $table_name = $wpdb->prefix . 'sdm_downloads';
26
-
27
- if($wpdb->get_var("show tables like '".$table_name."'") != $table_name) {
28
-
29
- $sql = 'CREATE TABLE '.$table_name.' (
30
  id mediumint(9) NOT NULL AUTO_INCREMENT,
31
  post_id mediumint(9) NOT NULL,
32
  post_title mediumtext NOT NULL,
33
  file_url mediumtext NOT NULL,
34
  visitor_ip mediumtext NOT NULL,
35
  date_time datetime DEFAULT "0000-00-00 00:00:00" NOT NULL,
 
36
  UNIQUE KEY id (id)
37
  );';
38
-
39
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
40
- dbDelta( $sql );
41
-
42
- add_option( 'sdm_db_version', $sdm_db_version );
43
- }
 
 
 
 
 
 
 
 
 
 
44
  }
45
 
46
  /*
47
- ** Handle Language Localization
48
- */
49
  add_action('plugins_loaded', 'sdm_plugins_loaded_tasks');
 
50
  function sdm_plugins_loaded_tasks() {
51
- //Load language
52
- load_plugin_textdomain( 'sdm_lang', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
53
-
54
- //Handle download request if any
55
- handle_sdm_download_via_direct_post();
 
 
 
56
  }
57
 
58
- /*
59
- ** Add a 'Settings' link to plugins list page
60
- */
61
- add_filter('plugin_action_links', 'sdm_settings_link', 10, 2 );
 
62
  function sdm_settings_link($links, $file) {
63
- static $this_plugin;
64
- if (!$this_plugin) $this_plugin = plugin_basename(__FILE__);
65
- if ($file == $this_plugin){
66
- $settings_link = '<a href="edit.php?post_type=sdm_downloads&page=settings" title="SDM Settings Page">'.__("Settings",'sdm_lang').'</a>';
67
- array_unshift($links, $settings_link);
68
- }
69
- return $links;
 
70
  }
71
-
72
  // Houston... we have lift-off!!
73
  class simpleDownloadManager {
74
-
75
- public function __construct() {
76
-
77
- if( is_admin()) {
78
- add_action( 'init', array( &$this, 'sdm_register_post_type' )); // Create 'sdm_downloads' custom post type
79
- add_action( 'init', array( &$this, 'sdm_create_taxonomies' )); // Register 'tags' and 'categories' taxonomies
80
- add_action( 'admin_menu', array( &$this, 'sdm_create_menu_pages' )); // Create admin pages
81
- add_action( 'add_meta_boxes', array( &$this, 'sdm_create_upload_metabox' )); // Create metaboxes
82
-
83
- add_action( 'save_post', array( &$this, 'sdm_save_description_meta_data' )); // Save 'description' metabox
84
- add_action( 'save_post', array( &$this, 'sdm_save_upload_meta_data' )); // Save 'upload file' metabox
85
- add_action( 'save_post', array( &$this, 'sdm_save_thumbnail_meta_data' )); // Save 'thumbnail' metabox
86
-
87
- add_action( 'admin_enqueue_scripts', array( &$this, 'sdm_admin_scripts' )); // Register admin scripts
88
- add_action( 'admin_print_styles', array( &$this, 'sdm_admin_styles' )); // Register admin styles
89
-
90
- add_action( 'admin_init', array( &$this, 'sdm_register_options' )); // Register admin options
91
-
92
- add_filter( 'post_row_actions',array( &$this, 'sdm_remove_view_link_cpt' )); // Remove 'View' link in CPT view
93
- }
94
- }
95
-
96
- public function sdm_admin_scripts() {
97
-
98
- global $current_screen, $post;
99
-
100
- if (is_admin() && $current_screen->post_type == 'sdm_downloads' && $current_screen->base == 'post') {
101
-
102
- // These scripts are needed for the media upload thickbox
103
- wp_enqueue_script('media-upload');
104
- wp_enqueue_script('thickbox');
105
- wp_register_script('sdm-upload', WP_SIMPLE_DL_MONITOR_URL.'/js/sdm_admin_scripts.js', array('jquery','media-upload','thickbox'));
106
- wp_enqueue_script('sdm-upload');
107
-
108
- // Pass postID for thumbnail deletion
109
- ?>
110
- <script type="text/javascript">
111
- var sdm_del_thumb_postid = '<?php echo $post->ID; ?>';
112
- </script>
 
 
 
113
  <?php
114
- }
115
-
116
- // Pass admin ajax url
117
- ?>
118
- <script type="text/javascript">
119
- var sdm_admin_ajax_url = { sdm_admin_ajax_url: '<?php echo admin_url('admin-ajax.php?action=ajax'); ?>' };
120
- var sdm_plugin_url = '<?php echo plugins_url(); ?>';
121
- </script>
122
- <?php
123
- }
124
-
125
- public function sdm_admin_styles() {
126
-
127
- wp_enqueue_style('thickbox'); // Needed for media upload thickbox
128
- wp_enqueue_style('sdm_admin_styles', WP_SIMPLE_DL_MONITOR_URL.'/css/sdm_admin_styles.css'); // Needed for media upload thickbox
129
- }
130
-
131
- public function sdm_register_post_type() {
132
-
133
- //*****
134
- //***** Create 'sdm_downloads' Custom Post Type
135
- $labels = array(
136
- 'name' => __('Downloads','sdm_lang'),
137
- 'singular_name' => __('Downloads','sdm_lang'),
138
- 'add_new' => __('Add New','sdm_lang'),
139
- 'add_new_item' => __('Add New','sdm_lang'),
140
- 'edit_item' => __('Edit Download','sdm_lang'),
141
- 'new_item' => __('New Download','sdm_lang'),
142
- 'all_items' => __('Downloads','sdm_lang'),
143
- 'view_item' => __('View Download','sdm_lang'),
144
- 'search_items' => __('Search Downloads','sdm_lang'),
145
- 'not_found' => __('No Downloads found','sdm_lang'),
146
- 'not_found_in_trash' => __('No Downloads found in Trash','sdm_lang'),
147
- 'parent_item_colon' => __('','sdm_lang'),
148
- 'menu_name' => __('Downloads','sdm_lang')
149
- );
150
- $args = array(
151
- 'labels' => $labels,
152
- 'public' => true,
153
- 'publicly_queryable' => true,
154
- 'show_ui' => true,
155
- 'show_in_menu' => true,
156
- 'query_var' => true,
157
- 'rewrite' => array( 'slug' => 'sdm_downloads' ),
158
- 'capability_type' => 'post',
159
- 'has_archive' => true,
160
- 'hierarchical' => false,
161
- 'menu_position' => null,
162
- 'supports' => array( 'title' )
163
- );
164
- register_post_type( 'sdm_downloads', $args );
165
- }
166
-
167
- public function sdm_create_taxonomies() {
168
-
169
- //*****
170
- //***** Create CATEGORIES Taxonomy
171
- $labels_tags = array(
172
- 'name' => _x( 'Categories', 'sdm_lang' ),
173
- 'singular_name' => _x( 'Category', 'sdm_lang' ),
174
- 'search_items' => __( 'Search Categories', 'sdm_lang' ),
175
- 'all_items' => __( 'All Categories', 'sdm_lang' ),
176
- 'parent_item' => __( 'Categories Genre', 'sdm_lang' ),
177
- 'parent_item_colon' => __( 'Categories Genre:', 'sdm_lang' ),
178
- 'edit_item' => __( 'Edit Category', 'sdm_lang' ),
179
- 'update_item' => __( 'Update Category', 'sdm_lang' ),
180
- 'add_new_item' => __( 'Add New Category', 'sdm_lang' ),
181
- 'new_item_name' => __( 'New Category', 'sdm_lang' ),
182
- 'menu_name' => __( 'Categories', 'sdm_lang' )
183
- );
184
- $args_tags = array(
185
- 'hierarchical' => true,
186
- 'labels' => $labels_tags,
187
- 'show_ui' => true,
188
- 'query_var' => true,
189
- 'rewrite' => array( 'slug' => 'sdm_categories' ),
190
- 'show_admin_column' => true
191
- );
192
- register_taxonomy( 'sdm_categories', array( 'sdm_downloads' ), $args_tags );
193
-
194
- //*****
195
- //***** Create TAGS Taxonomy
196
- $labels_tags = array(
197
- 'name' => _x( 'Tags', 'sdm_lang' ),
198
- 'singular_name' => _x( 'Tag', 'sdm_lang' ),
199
- 'search_items' => __( 'Search Tags', 'sdm_lang' ),
200
- 'all_items' => __( 'All Tags', 'sdm_lang' ),
201
- 'parent_item' => __( 'Tags Genre', 'sdm_lang' ),
202
- 'parent_item_colon' => __( 'Tags Genre:', 'sdm_lang' ),
203
- 'edit_item' => __( 'Edit Tag', 'sdm_lang' ),
204
- 'update_item' => __( 'Update Tag', 'sdm_lang' ),
205
- 'add_new_item' => __( 'Add New Tag', 'sdm_lang' ),
206
- 'new_item_name' => __( 'New Tag', 'sdm_lang' ),
207
- 'menu_name' => __( 'Tags', 'sdm_lang' )
208
- );
209
- $args_tags = array(
210
- 'hierarchical' => false,
211
- 'labels' => $labels_tags,
212
- 'show_ui' => true,
213
- 'query_var' => true,
214
- 'rewrite' => array( 'slug' => 'sdm_tags' ),
215
- 'show_admin_column' => true
216
- );
217
- register_taxonomy( 'sdm_tags', array( 'sdm_downloads' ), $args_tags );
218
- }
219
-
220
- public function sdm_create_menu_pages() {
221
-
222
- //*****
223
- //***** If user clicked to download the bulk export log
224
- if(isset($_GET['download_log']))
225
- {
226
- global $wpdb;
227
- $csv_output = '';
228
- $table = $wpdb->prefix.'sdm_downloads';
229
-
230
- $result = mysql_query("SHOW COLUMNS FROM ".$table."");
231
-
232
- $i = 0;
233
- if (mysql_num_rows($result) > 0) {
234
- while ($row = mysql_fetch_assoc($result)) {
235
- $csv_output = $csv_output . $row['Field'].",";
236
- $i++;
237
- }
238
- }
239
- $csv_output .= "\n";
240
-
241
- $values = mysql_query("SELECT * FROM ".$table."");
242
- while ($rowr = mysql_fetch_row($values)) {
243
- for ($j=0; $j<$i; $j++) {
244
- $csv_output .= $rowr[$j].",";
245
- }
246
- $csv_output .= "\n";
247
- }
248
-
249
- header("Pragma: public");
250
- header("Expires: 0");
251
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
252
- header("Cache-Control: private", false);
253
- header("Content-Type: application/octet-stream");
254
- header("Content-Disposition: attachment; filename=\"report.csv\";" );
255
- header("Content-Transfer-Encoding: binary");
256
-
257
- echo $csv_output;
258
- exit;
259
- }
260
-
261
- //*****
262
- //***** Create the 'logs' and 'settings' submenu pages
263
- $sdm_logs_page = add_submenu_page( 'edit.php?post_type=sdm_downloads', __('Logs', 'sdm_lang'), __('Logs', 'sdm_lang'), 'manage_options', 'logs', 'sdm_create_logs_page' );
264
- $sdm_settings_page = add_submenu_page( 'edit.php?post_type=sdm_downloads', __('Settings', 'sdm_lang'), __('Settings', 'sdm_lang'), 'manage_options', 'settings', array( &$this, 'sdm_create_settings_page' ));
265
- }
266
-
267
- public function sdm_create_settings_page()
268
- {
269
- echo '<div class="wrap">';
270
- echo '<div id="poststuff"><div id="post-body">';
271
- ?>
272
- <h2><?php _e('Simple Download Monitor Settings Page', 'sdm_lang') ?></h2>
273
-
274
- <div style="background: #FFF6D5; border: 1px solid #D1B655; color: #3F2502; padding: 15px 10px">
275
- <a href="http://www.tipsandtricks-hq.com/development-center" target="_blank">Follow us</a> on Twitter, Google+ or via Email to stay upto date about the new features of this plugin.
276
- </div>
277
-
278
- <!-- settings page form -->
279
- <form method="post" action="options.php">
280
-
281
- <!-- BEGIN ADMIN OPTIONS DIV -->
282
- <div id="sdm_admin_opts_div" class="sdm_sliding_div_title">
283
- <div class="sdm_slider_title">
284
- <?php _e('Admin Options', 'sdm_lang') ?>
285
- </div>
286
- <div class="sdm_desc">
287
- <?php _e("Control various plugin features.", 'sdm_lang') ?>
288
- </div>
 
 
 
289
  </div>
290
- <div id="sliding_div1" class="slidingDiv">
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  <?php
292
  // This prints out all hidden setting fields
293
- do_settings_sections( 'admin_options_section' );
294
- settings_fields( 'sdm_downloads_options' );
295
-
296
- submit_button();
297
- ?>
298
- </div>
299
- <!-- END ADMIN OPTIONS DIV -->
300
 
301
- <!-- BEGIN COLORS DIV -->
302
- <div id="sdm_color_opts_div" class="sdm_sliding_div_title">
303
- <div class="sdm_slider_title">
304
- <?php _e('Color Options', 'sdm_lang') ?>
305
  </div>
306
- <div class="sdm_desc">
307
- <?php _e("Adjust color options", 'sdm_lang') ?>
 
 
 
 
 
 
 
 
308
  </div>
309
- </div>
310
- <div id="sliding_div2" class="slidingDiv">
311
  <?php
312
  // This prints out all hidden setting fields
313
- do_settings_sections( 'sdm_colors_section' );
314
- settings_fields( 'sdm_downloads_options' );
315
 
316
- submit_button();
317
  ?>
318
- </div>
319
- <!-- END COLORS OPTIONS DIV -->
320
-
321
- <!-- End of settings page form -->
322
  </form>
323
-
324
- <div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
325
- <p>If you need a feature rich and supported plugin for selling your digital items then checkout our <a href="http://www.tipsandtricks-hq.com/wordpress-estore-plugin-complete-solution-to-sell-digital-products-from-your-wordpress-blog-securely-1059" target="_blank">WP eStore Plugin</a>
326
- </p>
327
- </div>
328
 
329
  <?php
330
- echo '</div></div>';//end of post-stuff
331
- echo '</div>';//end of wrap
332
- }
333
-
334
- public function sdm_create_upload_metabox() {
335
-
336
- //*****
337
- //***** Create metaboxes for the custom post type
338
- add_meta_box('sdm_description_meta_box',
339
- __('Description', 'sdm_lang'),
340
- array( &$this, 'display_sdm_description_meta_box'),
341
- 'sdm_downloads', 'normal', 'default'
342
- );
343
- add_meta_box('sdm_upload_meta_box',
344
- __('Upload File', 'sdm_lang'),
345
- array( &$this, 'display_sdm_upload_meta_box'),
346
- 'sdm_downloads', 'normal', 'default'
347
- );
348
- add_meta_box('sdm_thumbnail_meta_box',
349
- __('File Thumbnail (Optional)', 'sdm_lang'),
350
- array( &$this, 'display_sdm_thumbnail_meta_box'),
351
- 'sdm_downloads', 'normal', 'default'
352
- );
353
- add_meta_box('sdm_shortcode_meta_box',
354
- __('Shortcodes', 'sdm_lang'),
355
- array( &$this, 'display_sdm_shortcode_meta_box'),
356
- 'sdm_downloads', 'normal', 'default'
357
- );
358
- add_meta_box('sdm_stats_meta_box',
359
- __('Statistics', 'sdm_lang'),
360
- array( &$this, 'display_sdm_stats_meta_box'),
361
- 'sdm_downloads', 'normal', 'default'
362
- );
363
- }
364
-
365
- public function display_sdm_description_meta_box( $post ) { // Description metabox
366
-
367
- _e('Add a description for this download item.','sdm_lang');
368
- echo '<br /><br />';
369
-
370
- $old_description = get_post_meta( $post->ID, 'sdm_description', true );
371
- ?>
372
  <textarea id="sdm_description" name="sdm_description" style="width:60%;height:40px;"><?php echo $old_description; ?></textarea>
373
  <?php
374
- wp_nonce_field( 'sdm_description_box_nonce', 'sdm_description_box_nonce_check' );
375
- }
376
-
377
- public function display_sdm_upload_meta_box( $post ) { // File Upload metabox
378
-
379
- $old_upload = get_post_meta( $post->ID, 'sdm_upload', true );
380
- $old_value = isset($old_upload) ? $old_upload : '';
381
- _e('Click "Select File" to upload (or choose) the file.', 'sdm_lang');
382
- ?>
383
  <br /><br />
384
- <input id="upload_image_button" type="button" class="button-primary" value="Select File" />
385
  <span style="margin-left:40px;"></span>
386
- <?php _e('File URL:', 'sdm_lang') ?> <input id="sdm_upload" type="text" size="150" name="sdm_upload" value="<?php echo $old_value; ?>" />
387
  <?php
388
- wp_nonce_field( 'sdm_upload_box_nonce', 'sdm_upload_box_nonce_check' );
389
- }
390
-
391
- public function display_sdm_thumbnail_meta_box( $post ) { // Thumbnail upload metabox
392
-
393
- $old_thumbnail = get_post_meta( $post->ID, 'sdm_upload_thumbnail', true );
394
- $old_value = isset($old_thumbnail) ? $old_thumbnail : '';
395
- _e('Click "Select Image" to upload (or choose) the file thumbnail image. This thumbnail image will be used to create a fancy file download box if you want to use it.', 'sdm_lang');
396
- echo '<br />';
397
- _e('Recommended image size is 75px by 75px.', 'sdm_lang');
398
- ?>
399
  <br /><br />
400
- <input id="upload_thumbnail_button" type="button" class="button-primary" value="<?php _e('Select Image', 'sdm_lang'); ?>" />
401
- <input id="remove_thumbnail_button" type="button" class="button" value="<?php _e('Remove Image', 'sdm_lang'); ?>" />
402
  <span style="margin-left:40px;"></span>
403
- <input id="sdm_upload_thumbnail" type="hidden" size="150" name="sdm_upload_thumbnail" value="<?php echo $old_value; ?>" />
404
  <span id="sdm_get_thumb">
405
- <?php
406
- if($old_value != '') {
407
- ?><img id="sdm_thumbnail_image" src="<?php echo $old_value; ?>" />
408
  <?php
409
- }
410
- ?></span><?php
411
- wp_nonce_field( 'sdm_thumbnail_box_nonce', 'sdm_thumbnail_box_nonce_check' );
412
- }
413
-
414
- public function display_sdm_shortcode_meta_box( $post ) { // Shortcode metabox
415
-
416
- _e('This is the shortcode which can used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter to add this shortcode to a post or page.','sdm_lang');
417
- echo '<br />';
418
- echo '[sdm-download id="'.$post->ID.'" fancy="0"]';
419
- echo '<br /><br />';
420
- _e('This shortcode may be used as a download counter.', 'sdm_lang');
421
- echo '<br />';
422
- echo '[sdm-download-counter id="'.$post->ID.'"]';
423
- }
424
-
425
- public function display_sdm_stats_meta_box( $post ) { // Stats metabox
426
-
427
- _e('These are the statistics for this download item.','sdm_lang');
428
- echo '<br /><br />';
429
-
430
- global $wpdb;
431
- $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$wpdb->prefix.'sdm_downloads WHERE post_id=%s', $post->ID));
432
- _e('Number of Downloads:', 'sdm_lang'); echo ' '.$wpdb->num_rows;
433
- }
434
-
435
- public function sdm_save_description_meta_data($post_id) { // Save Description metabox
436
-
437
- if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
438
- return;
439
- if( !isset( $_POST['sdm_description_box_nonce_check'] ) || !wp_verify_nonce( $_POST['sdm_description_box_nonce_check'], 'sdm_description_box_nonce' ) )
440
- return;
441
-
442
- if( isset( $_POST['sdm_description'] ) ) {
443
- update_post_meta( $post_id, 'sdm_description', $_POST['sdm_description'] );
444
- }
445
-
446
- }
447
-
448
- public function sdm_save_upload_meta_data($post_id) { // Save File Upload metabox
449
-
450
- if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
451
- return;
452
- if( !isset( $_POST['sdm_upload_box_nonce_check'] ) || !wp_verify_nonce( $_POST['sdm_upload_box_nonce_check'], 'sdm_upload_box_nonce' ) )
453
- return;
454
-
455
- if( isset( $_POST['sdm_upload'] ) ) {
456
- update_post_meta( $post_id, 'sdm_upload', $_POST['sdm_upload'] );
457
- }
458
- }
459
-
460
- public function sdm_save_thumbnail_meta_data($post_id) { // Save Thumbnail Upload metabox
461
-
462
- if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
463
- return;
464
- if( !isset( $_POST['sdm_thumbnail_box_nonce_check'] ) || !wp_verify_nonce( $_POST['sdm_thumbnail_box_nonce_check'], 'sdm_thumbnail_box_nonce' ) )
465
- return;
466
-
467
- if( isset( $_POST['sdm_upload_thumbnail'] ) ) {
468
- update_post_meta( $post_id, 'sdm_upload_thumbnail', $_POST['sdm_upload_thumbnail'] );
469
- }
470
- }
471
-
472
- public function sdm_remove_view_link_cpt( $action ) {
473
-
474
- unset ($action['view']);
475
  return $action;
476
- }
477
-
478
- public function sdm_register_options() {
479
-
480
- register_setting( 'sdm_downloads_options', 'sdm_downloads_options' );
481
- add_settings_section( 'admin_options', __('Admin Options', 'sdm_lang'), array( $this, 'admin_options_cb' ), 'admin_options_section' );
482
- add_settings_section( 'sdm_colors', __('Colors', 'sdm_lang'), array( $this, 'sdm_colors_cb' ), 'sdm_colors_section' );
483
-
484
- add_settings_field( 'admin_tinymce_button', __('Remove Tinymce Button', 'sdm_lang'), array( $this, 'admin_tinymce_button_cb' ), 'admin_options_section', 'admin_options' );
485
- add_settings_field( 'download_button_color', __('Download Button Color', 'sdm_lang'), array( $this, 'download_button_color_cb' ), 'sdm_colors_section', 'sdm_colors' );
486
- }
487
- public function admin_options_cb() {
488
- _e('Admin options settings', 'sdm_lang');
489
- }
490
- public function sdm_colors_cb() {
491
- _e('Front End colors settings', 'sdm_lang');
492
- }
493
- public function admin_tinymce_button_cb() {
494
- $main_opts = get_option('sdm_downloads_options');
495
- echo '<input name="sdm_downloads_options[admin_tinymce_button]" id="admin_tinymce_button" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset($main_opts['admin_tinymce_button']), false ) . ' /> ';
496
- _e('Removes the SDM Downloads button from the WP content editor.', 'sdm_lang');
497
- }
498
- public function download_button_color_cb() {
499
- $main_opts = get_option('sdm_downloads_options');
500
- $color_opt = $main_opts['download_button_color'];
501
- $color_opts = array( __('Green','sdm_lang'), __('Blue','sdm_lang'),__('Purple','sdm_lang'),__('Teal','sdm_lang'),__('Dark Blue','sdm_lang'),__('Black','sdm_lang'),__('Grey','sdm_lang'),__('Pink','sdm_lang'),__('Orange','sdm_lang'),__('White','sdm_lang') );
502
- echo '<select name="sdm_downloads_options[download_button_color]" id="download_button_color" class="sdm_opts_ajax_dropdowns">';
503
- if(isset($color_opt)) {
504
- echo '<option value="'.$color_opt.'" selected="selected">'.$color_opt.' (current)</option>';
505
- }
506
- foreach ($color_opts as $color) {
507
- echo '<option value="'.$color.'" '.$sel_color.'>'.$color.'</option>';
508
- }
509
- echo '</select> ';
510
- _e('Adjusts the color of the "Download Now" button.', 'sdm_lang');
511
- }
512
-
 
 
 
 
513
  }
 
514
  $simpleDownloadManager = new simpleDownloadManager();
515
 
516
  /*
517
- **
518
- ** Logs Page
519
- **
520
- */
521
  //*****
522
  //***** Check WP_List_Table exists
523
- if(!class_exists('WP_List_Table')){
524
  require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
525
  }
526
 
527
  //*****
528
  //***** Define our new Table
529
  class sdm_List_Table extends WP_List_Table {
530
-
531
-
532
- function __construct(){
533
-
534
  global $status, $page;
535
-
536
  //Set parent defaults
537
- parent::__construct( array(
538
- 'singular' => 'Download', //singular name of the listed records
539
- 'plural' => 'Downloads', //plural name of the listed records
540
- 'ajax' => false //does this table support ajax?
541
- ) );
542
-
543
  }
544
-
545
- function column_default($item, $column_name){
546
-
547
- switch($column_name){
548
  case 'URL':
549
  case 'visitor_ip':
550
  case 'date':
551
  return $item[$column_name];
 
 
552
  default:
553
- return print_r($item,true); //Show the whole array for troubleshooting purposes
554
  }
555
  }
556
-
557
- function column_title($item){
558
-
559
  //Build row actions
560
  $actions = array(
561
- 'edit' => sprintf('<a href="'.admin_url( 'post.php?post='.$item['ID'].'&action=edit' ).'">Edit</a>'),
562
- 'delete' => sprintf('<a href="?post_type=sdm_downloads&page=%s&action=%s&download=%s&datetime=%s">Delete</a>',$_REQUEST['page'],'delete',$item['ID'],$item['date'])
563
  );
564
-
565
  //Return the title contents
566
  return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
567
- /*$1%s*/ $item['title'],
568
- /*$2%s*/ $item['ID'],
569
- /*$3%s*/ $this->row_actions($actions)
570
  );
571
  }
572
-
573
- function column_cb($item){
574
-
575
  return sprintf(
576
- '<input type="checkbox" name="%1$s[]" value="%2$s" />',
577
- /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("Download")
578
- /*$2%s*/ $item['ID'].'|'.$item['date'] //The value of the checkbox should be the record's id
579
  );
580
  }
581
-
582
- function get_columns(){
583
-
584
  $columns = array(
585
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
586
- 'title' => __('Title','sdm_lang'),
587
- 'URL' => __('File','sdm_lang'),
588
- 'visitor_ip' => __('Visitor IP','sdm_lang'),
589
- 'date' => __('Date','sdm_lang')
 
590
  );
591
  return $columns;
592
  }
593
-
594
  function get_sortable_columns() {
595
-
596
  $sortable_columns = array(
597
- 'title' => array('title',false), //true means it's already sorted
598
- 'URL' => array('URL',false),
599
- 'visitor_ip' => array('visitor_ip',false),
600
- 'date' => array('date',false)
 
601
  );
602
  return $sortable_columns;
603
  }
604
-
605
  function get_bulk_actions() {
606
-
607
  $actions = array();
608
- $actions['delete2'] = __( 'Delete Permanently', 'sdm_lang' );
609
- $actions['export_all'] = __( 'Export All as Excel', 'sdm_lang' );
610
  //$actions['export-selected'] = __( 'Export Selected', 'sdm_lang' );
611
 
612
  return $actions;
613
  }
614
-
615
  function process_bulk_action() {
616
-
617
- // security check!
618
- if ( isset( $_POST['_wpnonce'] ) && ! empty( $_POST['_wpnonce'] ) ) {
619
 
620
- $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
621
- $action = 'bulk-' . $this->_args['plural'];
622
 
623
- if ( ! wp_verify_nonce( $nonce, $action ) )
624
- wp_die( 'Nope! Security check failed!' );
625
 
 
 
626
  }
627
 
628
  $action = $this->current_action();
629
-
630
- // If bulk 'Export All' was clicked
631
- if( 'export_all' === $this->current_action() ) {
632
-
633
- echo '<div id="message" class="updated"><p><strong><a id="sdm_download_export" href="?post_type=sdm_downloads&page=logs&download_log">Download Export File</a></strong></p></div>';
634
- }
635
-
636
- // if bulk 'Delete Permanently' was clicked
637
- if( 'delete2' === $this->current_action() ) {
638
-
639
- if( !isset($_POST['download']) || $_POST['download'] == null) {
640
- echo '<div id="message" class="updated fade"><p><strong>No entries were selected.</strong></p><p><em>Click to Dismiss</em></p></div>';
641
- return;
642
- }
643
-
644
- foreach($_POST['download'] as $item) {
645
- $str_tok_id = substr($item, 0, strpos($item, '|'));
646
- $str_tok_datetime = substr($item,strpos($item,'|')+1);
647
-
648
- global $wpdb;
649
- $del_row = $wpdb->query(
650
- 'DELETE FROM '.$wpdb->prefix.'sdm_downloads
651
- WHERE post_id = "'.$str_tok_id.'"
652
- AND date_time = "'.$str_tok_datetime.'"'
653
- );
654
- }
655
- if($del_row) {
656
- echo '<div id="message" class="updated fade"><p><strong>Entries Deleted!</strong></p><p><em>Click to Dismiss</em></p></div>';
657
- }
658
- else {
659
- echo '<div id="message" class="updated fade"><p><strong>Error</strong></p><p><em>Click to Dismiss</em></p></div>';
660
- }
661
- }
662
-
663
- // If single entry 'Delete' was clicked
664
- if( 'delete'===$this->current_action() ) {
665
-
666
- $item_id = isset($_GET['download']) ? strtok($_GET['download'], '|') : '';
667
- $item_datetime = isset($_GET['datetime']) ? $_GET['datetime'] : '';
668
-
669
- global $wpdb;
670
- $del_row = $wpdb->query(
671
- 'DELETE FROM '.$wpdb->prefix.'sdm_downloads
672
- WHERE post_id = "'.$item_id.'"
673
- AND date_time = "'.$item_datetime.'"'
674
- );
675
- if($del_row) {
676
- echo '<div id="message" class="updated fade"><p><strong>Entry Deleted!</strong></p><p><em>Click to Dismiss</em></p></div>';
677
- }
678
- else {
679
- echo '<div id="message" class="updated fade"><p><strong>Error</strong></p><p><em>Click to Dismiss</em></p></div>';
680
- }
681
  }
682
-
683
  }
684
-
685
  function prepare_items() {
686
-
687
  global $wpdb; //This is used only if making any database queries
688
  $per_page = 10;
689
  $columns = $this->get_columns();
690
  $hidden = array();
691
  $sortable = $this->get_sortable_columns();
692
-
693
-
694
  $this->_column_headers = array($columns, $hidden, $sortable);
695
  $this->process_bulk_action();
 
696
  //$data = $this->example_data;
697
-
698
- function usort_reorder($a,$b){
699
  $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'title'; //If no sort, default to title
700
  $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
701
  $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
702
- return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
703
  }
704
-
705
- $data_results = $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$wpdb->prefix.'sdm_downloads', null ));
706
- $data = array();
707
- foreach ($data_results as $data_result) {
708
- $data[] = array( 'ID' => $data_result->post_id, 'title' => $data_result->post_title, 'URL' => $data_result->file_url, 'visitor_ip' => $data_result->visitor_ip, 'date' => $data_result->date_time );
709
- }
710
-
711
-
712
  usort($data, 'usort_reorder');
713
  $current_page = $this->get_pagenum();
714
  $total_items = count($data);
715
- $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
716
-
717
  $this->items = $data;
718
- $this->set_pagination_args( array(
719
- 'total_items' => $total_items, //WE have to calculate the total number of items
720
- 'per_page' => $per_page, //WE have to determine how many items to show on a page
721
- 'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages
722
- ) );
723
  }
724
-
725
  }
726
- function sdm_create_logs_page(){
727
-
 
728
  //Create an instance of our package class...
729
  $sdmListTable = new sdm_List_Table();
730
  //Fetch, prepare, sort, and filter our data...
731
  $sdmListTable->prepare_items();
732
-
733
  ?>
734
  <div class="wrap">
735
-
736
  <div id="icon-users" class="icon32"><br/></div>
737
  <h2><?php _e('Download Logs', 'sdm_lang'); ?></h2>
738
-
739
  <div style="background:#ECECEC;border:1px solid #CCC;padding:0 10px;margin-top:5px;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;">
740
  <p><?php _e('This page lists all tracked downloads.', 'sdm_lang'); ?></p>
741
  </div>
742
-
743
  <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
744
  <form id="sdm_downloads-filter" method="post">
745
  <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
746
  <!-- Now we can render the completed list table -->
747
- <?php $sdmListTable->display() ?>
748
  </form>
749
-
750
  </div>
751
  <script type="text/javascript">
752
- jQuery(document).ready(function($){
753
- $('.fade').click(function(){$(this).fadeOut('slow');});
754
- });
755
- </script>
 
 
756
  <?php
757
  }
758
 
759
- /*
760
- ** Register Download Shortcode
761
- */
762
- add_action( 'init', 'sdm_register_shortcodes' );
763
- function sdm_register_shortcodes() {
764
-
765
- add_shortcode('sdm-download', 'sdm_create_download_shortcode' ); // For download shortcode
766
- add_shortcode('sdm-download-counter', 'sdm_create_counter_shortcode' ); // For counter shortcode
767
- }
768
- // Create Download Shortcode
769
- function sdm_create_download_shortcode( $atts ) {
770
-
771
- extract( shortcode_atts( array(
772
- 'id' => 'id',
773
- 'fancy' => '0'
774
- ), $atts ) );
775
-
776
- // Check to see if the download link cpt is password protected
777
- $get_cpt_object = get_post($id);
778
- $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected;
779
-
780
- // Get CPT thumbnail
781
- $item_download_thumbnail = get_post_meta( $id, 'sdm_upload_thumbnail', true );
782
- $isset_download_thumbnail = isset($item_download_thumbnail) && !empty($item_download_thumbnail) ? '<img class="sdm_download_thumbnail_image" src="'.$item_download_thumbnail.'" />' : '';
783
-
784
- // Get CPT title
785
- $item_title = get_the_title( $id );
786
- $isset_item_title = isset($item_title) && !empty($item_title) ? $item_title : '';
787
-
788
- // Get CPT description
789
- $item_description = get_post_meta( $id, 'sdm_description', true );
790
- $isset_item_description = isset($item_description) && !empty($item_description) ? $item_description : '';
791
-
792
- // Get CPT download link
793
- $item_link = get_post_meta( $id, 'sdm_upload', true );
794
- $isset_item_link = isset($item_link) && !empty($item_link) ? $item_link : '';
795
-
796
- // See if user color option is selected
797
- $main_opts = get_option('sdm_downloads_options');
798
- $color_opt = $main_opts['download_button_color'];
799
- $def_color = isset($color_opt) ? str_replace(' ', '', strtolower($color_opt)) : __('green', 'sdm_lang');
800
-
801
- //Generate the download now button code
802
- $homepage = get_bloginfo('url');
803
- $download_url = $homepage. '/?smd_process_download=1&download_id='.$id;
804
- $download_button_code = '<a href="'.$download_url.'" class="sdm_download '.$def_color.'" title="'.$isset_item_title.'">'.__('Download Now!', 'sdm_lang').'</a>';
805
-
806
- if($cpt_is_password !== 'no'){//This is a password protected download so replace the download now button with password requirement
807
- $download_button_code = sdm_get_password_entry_form($id);
808
- }
809
- //End of download now button code generation
810
-
811
- if ($fancy == '0') {
812
- $data = '<div class="sdm_download_link">'.$download_button_code.'</div>';
813
- return $data;
814
- }
815
-
816
- if ($fancy == '1') {
817
- // Prepare shortcode
818
- $data = '<div class="sdm_download_item">';
819
- $data .= '<div class="sdm_download_item_top">';
820
- $data .= '<div class="sdm_download_thumbnail">'.$isset_download_thumbnail.'</div>';
821
- $data .= '<div class="sdm_download_title">'.$isset_item_title.'</div>';
822
- $data .= '</div>';//End of .sdm_download_item_top
823
- $data .= '<div style="clear:both;"></div>';
824
- $data .= '<div class="sdm_download_description">'.$isset_item_description.'</div>';
825
- $data .= '<div class="sdm_download_link">'.$download_button_code.'</div>';
826
- $data .= '</div>';
827
- // Render shortcode
828
- return $data;
829
- }
830
  }
831
 
832
- function sdm_get_password_entry_form($id)
833
- {
834
- $data = __('Enter Password to Download:','sdm_lang');
835
- $data .= '<form method="post">';
836
- $data .= '<input type="text" class="pass_text" /> ';
837
- $data .= '<input type="button" class="pass_sumbit" value="'.__('Submit','sdm_lang').'" />';
838
- $data .= '<input type="hidden" value="'.$id.'" />';
839
- $data .= '</form>';
840
- return $data;
841
- }
842
 
843
- // Create Counter Shortcode
844
- function sdm_create_counter_shortcode( $atts ) {
845
-
846
- extract( shortcode_atts( array(
847
- 'id' => 'id'
848
- ), $atts ) );
849
-
850
- // Get number of downloads by counting db columns matching postID
851
- global $wpdb;
852
- $table = $wpdb->prefix.'sdm_downloads';
853
- $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$table.' WHERE post_id=%s', $id));
854
-
855
- // Return result
856
- return $wpdb->num_rows.' '.__('Downloads','sdm_lang');
857
  }
858
 
 
 
 
 
 
 
 
 
859
 
 
 
 
 
 
 
 
 
 
 
860
 
861
- /*
862
- ** Register scripts for front-end posts/pages
863
- */
864
- add_action( 'wp_enqueue_scripts', 'sdm_wp_scripts' );
865
- function sdm_wp_scripts() {
866
-
867
- wp_enqueue_style( 'sdm-styles', WP_SIMPLE_DL_MONITOR_URL. '/css/sdm_wp_styles.css' );
868
- wp_register_script('sdm-scripts', WP_SIMPLE_DL_MONITOR_URL. '/js/sdm_wp_scripts.js', array( 'jquery' ) );
869
- wp_enqueue_script('sdm-scripts');
870
-
871
- // Localize ajax script for frontend
872
- wp_localize_script( 'sdm-scripts', 'sdm_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
873
  }
874
 
875
- function handle_sdm_download_via_direct_post()
876
- {
877
- if(isset($_REQUEST['smd_process_download']) && $_REQUEST['smd_process_download'] == '1')
878
- {
879
- $download_id = strip_tags($_REQUEST['download_id']);
880
- $download_title = get_the_title( $download_id );
881
- $download_link = get_post_meta( $download_id, 'sdm_upload', true );
882
- $ipaddress = $_SERVER["REMOTE_ADDR"];
883
- $date_time = current_time( 'mysql' );
884
-
885
- global $wpdb;
886
- $table = $wpdb->prefix . 'sdm_downloads';
887
- $data = array(
888
- 'post_id' => $download_id,
889
- 'post_title' => $download_title,
890
- 'file_url' => $download_link,
891
- 'visitor_ip' => $ipaddress,
892
- 'date_time' => $date_time
893
- );
894
-
895
- $insert_table = $wpdb->insert( $table, $data );
896
-
897
- if ($insert_table) {//Download request was logged successfully
898
- sdm_redirect_to_url($download_link);
899
- }
900
- else {//Failed to log the download request
901
- wp_die ("Error! Failed to log the download request in the database table");
902
- }
903
- exit;
904
- }
905
- }
906
-
907
- function sdm_redirect_to_url($url,$delay='0',$exit='1')
908
- {
909
- if(empty($url)){
910
- echo "<strong>Error! The URL value is empty. Please specify a correct URL value to redirect to!</strong>";
911
- exit;
912
- }
913
- if (!headers_sent()){
914
- header('Location: ' . $url);
915
- }
916
- else{
917
- echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'" />';
918
- }
919
- if($exit == '1'){//exit
920
- exit;
921
- }
922
  }
923
 
924
  // Tinymce Button Populate Post ID's
925
- add_action( 'wp_ajax_nopriv_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call' );
926
- add_action( 'wp_ajax_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call' );
 
927
  function sdm_tiny_get_post_ids_ajax_call() {
928
-
929
- $args = array(
930
- 'post_type' => 'sdm_downloads',
931
- );
932
- $loop = new WP_Query($args);
933
- $test = '';
934
- foreach ($loop->posts as $loop_post) {
935
- //$test .= $loop_post->ID.'|'.$loop_post->post_title.'_';
936
- $test[] = array('post_id' => $loop_post->ID, 'post_title' => $loop_post->post_title);
937
- }
938
-
939
- $response = json_encode( array( 'success' => true, 'test' => $test ));
940
-
941
- header( 'Content-Type: application/json' );
942
- echo $response;
943
- exit;
944
  }
 
945
  // Remove Thumbnail Image
946
- add_action( 'wp_ajax_nopriv_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call' );
947
- add_action( 'wp_ajax_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call' );
 
948
  function sdm_remove_thumbnail_image_ajax_call() {
949
-
950
- $post_id = $_POST['post_id_del'];
951
- $success = delete_post_meta( $post_id, 'sdm_upload_thumbnail' );
952
- if($success) {
953
- $response = json_encode( array( 'success' => true ));
954
- }
955
-
956
- header( 'Content-Type: application/json' );
957
- echo $response;
958
- exit;
959
  }
 
960
  // Check download password
961
- add_action( 'wp_ajax_nopriv_sdm_check_pass', 'sdm_check_pass_ajax_call' );
962
- add_action( 'wp_ajax_sdm_check_pass', 'sdm_check_pass_ajax_call' );
 
963
  function sdm_check_pass_ajax_call() {
964
-
965
- $button_id = $_POST['button_id']; // Get button cpt id
966
- $pass_val = $_POST['pass_val']; // Get password attempt
967
- $success = '';
968
- $download_link = '';
969
-
970
- // Get post object
971
- $post_object = get_post($button_id);
972
- // Get post password
973
- $post_pass = $post_object->post_password;
974
-
975
- // Check if password is a match
976
- if($post_pass != $pass_val) { // Match is a failure
977
-
978
- $success = 'no'; // Pass back to ajax
979
- }
980
- else { // Match is a success
981
-
982
- $success = 'yes'; // Pass back to ajax
983
-
984
- $download_id = $button_id;
985
- $download_title = get_the_title( $download_id );
986
- $download_link = get_post_meta( $download_id, 'sdm_upload', true );
987
- $ipaddress = $_SERVER["REMOTE_ADDR"];
988
- $date_time = current_time( 'mysql' );
989
-
990
- global $wpdb;
991
- $table = $wpdb->prefix . 'sdm_downloads';
992
- $data = array(
993
- 'post_id' => $download_id,
994
- 'post_title' => $download_title,
995
- 'file_url' => $download_link,
996
- 'visitor_ip' => $ipaddress,
997
- 'date_time' => $date_time
998
- );
999
-
1000
- $insert_table = $wpdb->insert( $table, $data );
1001
- }
1002
-
1003
- // Generate ajax response
1004
- $response = json_encode( array( 'success' => $success, 'url' => $download_link ));
1005
- header( 'Content-Type: application/json' );
1006
- echo $response;
1007
- exit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1008
  }
1009
 
1010
  /*
1011
- ** Setup Sortable Columns
1012
- */
1013
- add_filter( 'manage_edit-sdm_downloads_columns', 'sdm_create_columns' ); // Define columns
1014
- add_filter( 'manage_edit-sdm_downloads_sortable_columns', 'sdm_downloads_sortable' ); // Make sortable
1015
- add_action( 'manage_sdm_downloads_posts_custom_column', 'sdm_downloads_columns_content', 10, 2 ); // Populate new columns
1016
- function sdm_create_columns( $cols ) {
1017
-
1018
- unset( $cols['title'] );
1019
- unset( $cols['taxonomy-sdm_tags'] );
1020
- unset( $cols['taxonomy-sdm_categories'] );
1021
- unset( $cols['date'] );
1022
-
1023
- $cols['sdm_downloads_thumbnail'] = __('Image', 'sdm_lang');
1024
- $cols['title'] = __('Title', 'sdm_lang');
1025
- $cols['sdm_downloads_id'] = __('ID', 'sdm_lang');
1026
- $cols['sdm_downloads_file'] = __('File', 'sdm_lang');
1027
- $cols['taxonomy-sdm_categories'] = __('Categories', 'sdm_lang');
1028
- $cols['taxonomy-sdm_tags'] = __('Tags', 'sdm_lang');
1029
- $cols['sdm_downloads_count'] = __('Downloads', 'sdm_lang');
1030
- $cols['date'] = __('Date Posted', 'sdm_lang');
1031
- return $cols;
 
 
 
1032
  }
1033
 
1034
- function sdm_downloads_sortable( $cols ) {
1035
-
1036
- $cols['sdm_downloads_id'] = 'sdm_downloads_id';
1037
- $cols['sdm_downloads_file'] = 'sdm_downloads_file';
1038
- $cols['sdm_downloads_count'] = 'sdm_downloads_count';
1039
- $cols['taxonomy-sdm_categories'] = 'taxonomy-sdm_categories';
1040
- $cols['taxonomy-sdm_tags'] = 'taxonomy-sdm_tags';
1041
- return $cols;
1042
  }
1043
 
1044
- function sdm_downloads_columns_content( $column_name, $post_ID ) {
1045
-
1046
- if ($column_name == 'sdm_downloads_thumbnail') {
1047
- $old_thumbnail = get_post_meta( $post_ID, 'sdm_upload_thumbnail', true );
1048
- $old_value = isset($old_thumbnail) ? $old_thumbnail : '';
1049
- echo '<p class="sdm_downloads_count"><img src="'.$old_value.'" style="width:50px;height:50px;" /></p>';
1050
- }
1051
- if ($column_name == 'sdm_downloads_id') {
1052
- echo '<p class="sdm_downloads_postid">'.$post_ID.'</p>';
1053
- }
1054
- if ($column_name == 'sdm_downloads_file') {
1055
- $old_file = get_post_meta( $post_ID, 'sdm_upload', true );
1056
- $file = isset($old_file) ? $old_file : '--';
1057
- echo '<p class="sdm_downloads_file">'.$file.'</p>';
1058
- }
1059
- if ($column_name == 'sdm_downloads_count') {
1060
- global $wpdb;
1061
- $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$wpdb->prefix.'sdm_downloads WHERE post_id=%s', $post_ID));
1062
- echo '<p class="sdm_downloads_count">'.$wpdb->num_rows.'</p>';
1063
- }
 
 
1064
  }
 
1065
  // Adjust admin column widths
1066
  add_action('admin_head', 'sdm_admin_column_width'); // Adjust column width in admin panel
 
1067
  function sdm_admin_column_width() {
1068
-
1069
  echo '<style type="text/css">';
1070
  echo '.column-sdm_downloads_thumbnail { width:75px !important; overflow:hidden }';
1071
  echo '.column-sdm_downloads_id { width:100px !important; overflow:hidden }';
1072
  echo '.column-taxonomy-sdm_categories { width:200px !important; overflow:hidden }';
1073
  echo '.column-taxonomy-sdm_tags { width:200px !important; overflow:hidden }';
1074
  echo '</style>';
1075
- }
1076
 
1077
  /*
1078
- ** Register Tinymce Button
1079
- */
1080
 
1081
  // First check if option is checked to disable tinymce button
1082
  $main_option = get_option('sdm_downloads_options');
1083
  $tiny_button_option = isset($main_option['admin_tinymce_button']);
1084
- if($tiny_button_option != true) {
1085
-
1086
- // Okay.. we're good. Add the button.
1087
- add_action( 'init', 'sdm_downloads_tinymce_button' );
1088
- function sdm_downloads_tinymce_button() {
1089
-
1090
- add_filter( 'mce_external_plugins', 'sdm_downloads_add_button' );
1091
- add_filter( 'mce_buttons', 'sdm_downloads_register_button' );
1092
- }
1093
- function sdm_downloads_add_button( $plugin_array ) {
1094
-
1095
- $plugin_array['sdm_downloads'] = WP_SIMPLE_DL_MONITOR_URL. '/tinymce/sdm_editor_plugin.js';
1096
- return $plugin_array;
1097
- }
1098
- function sdm_downloads_register_button( $buttons ) {
1099
-
1100
- //array_push( $buttons, 'sdm_downloads' );
1101
- $buttons[] = 'sdm_downloads';
1102
- return $buttons;
1103
- }
 
 
 
 
1104
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  * Plugin Name: Simple Download Monitor
4
  * Plugin URI: http://www.tipsandtricks-hq.com/development-center
5
  * Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
6
+ * Version: 2.9
7
  * Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
8
  * Author URI: http://www.tipsandtricks-hq.com/development-center
9
  * License: GPL2
10
  */
 
11
  define('WP_SIMPLE_DL_MONITOR_DIR_NAME', dirname(plugin_basename(__FILE__)));
12
+ define('WP_SIMPLE_DL_MONITOR_URL', plugins_url('', __FILE__));
13
+ define('WP_SIMPLE_DL_MONITOR_PATH', plugin_dir_path(__FILE__));
14
 
15
  global $sdm_db_version;
16
+ $sdm_db_version = '1.1';
17
+
18
+ //File includes
19
+ include_once('sdm-shortcodes.php');
20
+ include_once('sdm-post-type-content-handler.php');
21
+
22
+ //Activation hook handler
23
+ register_activation_hook(__FILE__, 'sdm_install_db_table');
24
 
 
25
  function sdm_install_db_table() {
26
+
27
+ global $wpdb;
28
+ global $sdm_db_version;
29
+
30
+ $table_name = $wpdb->prefix . 'sdm_downloads';
31
+
32
+ $sql = 'CREATE TABLE ' . $table_name . ' (
 
 
33
  id mediumint(9) NOT NULL AUTO_INCREMENT,
34
  post_id mediumint(9) NOT NULL,
35
  post_title mediumtext NOT NULL,
36
  file_url mediumtext NOT NULL,
37
  visitor_ip mediumtext NOT NULL,
38
  date_time datetime DEFAULT "0000-00-00 00:00:00" NOT NULL,
39
+ visitor_country mediumtext NOT NULL,
40
  UNIQUE KEY id (id)
41
  );';
42
+
43
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
44
+ dbDelta($sql);
45
+
46
+ update_option('sdm_db_version', $sdm_db_version);
47
+
48
+ }
49
+
50
+ function sdm_db_update_check() {
51
+ if (is_admin()) {//Check if DB needs to be upgraded
52
+ global $sdm_db_version;
53
+ $inst_db_version = get_option('sdm_db_version');
54
+ if ($inst_db_version != $sdm_db_version) {
55
+ sdm_install_db_table();
56
+ }
57
+ }
58
  }
59
 
60
  /*
61
+ * * Handle Plugins loaded tasks
62
+ */
63
  add_action('plugins_loaded', 'sdm_plugins_loaded_tasks');
64
+
65
  function sdm_plugins_loaded_tasks() {
66
+ //Load language
67
+ load_plugin_textdomain('sdm_lang', false, dirname(plugin_basename(__FILE__)) . '/langs/');
68
+
69
+ //Handle db upgrade stuff
70
+ sdm_db_update_check();
71
+
72
+ //Handle download request if any
73
+ handle_sdm_download_via_direct_post();
74
  }
75
 
76
+ /*
77
+ * * Add a 'Settings' link to plugins list page
78
+ */
79
+ add_filter('plugin_action_links', 'sdm_settings_link', 10, 2);
80
+
81
  function sdm_settings_link($links, $file) {
82
+ static $this_plugin;
83
+ if (!$this_plugin)
84
+ $this_plugin = plugin_basename(__FILE__);
85
+ if ($file == $this_plugin) {
86
+ $settings_link = '<a href="edit.php?post_type=sdm_downloads&page=settings" title="SDM Settings Page">' . __("Settings", 'sdm_lang') . '</a>';
87
+ array_unshift($links, $settings_link);
88
+ }
89
+ return $links;
90
  }
91
+
92
  // Houston... we have lift-off!!
93
  class simpleDownloadManager {
94
+
95
+ public function __construct() {
96
+
97
+ add_action('init', array(&$this, 'sdm_register_post_type')); // Create 'sdm_downloads' custom post type
98
+ add_action('init', array(&$this, 'sdm_create_taxonomies')); // Register 'tags' and 'categories' taxonomies
99
+ add_action('init', 'sdm_register_shortcodes'); //Register the shortcodes
100
+ add_action('wp_enqueue_scripts', array(&$this, 'sdm_frontend_scripts')); // Register frontend scripts
101
+
102
+ if (is_admin()) {
103
+ add_action('admin_menu', array(&$this, 'sdm_create_menu_pages')); // Create admin pages
104
+ add_action('add_meta_boxes', array(&$this, 'sdm_create_upload_metabox')); // Create metaboxes
105
+
106
+ add_action('save_post', array(&$this, 'sdm_save_description_meta_data')); // Save 'description' metabox
107
+ add_action('save_post', array(&$this, 'sdm_save_upload_meta_data')); // Save 'upload file' metabox
108
+ add_action('save_post', array(&$this, 'sdm_save_thumbnail_meta_data')); // Save 'thumbnail' metabox
109
+
110
+ add_action('admin_enqueue_scripts', array(&$this, 'sdm_admin_scripts')); // Register admin scripts
111
+ add_action('admin_print_styles', array(&$this, 'sdm_admin_styles')); // Register admin styles
112
+
113
+ add_action('admin_init', array(&$this, 'sdm_register_options')); // Register admin options
114
+
115
+ add_filter('post_row_actions', array(&$this, 'sdm_remove_view_link_cpt'), 10, 2); // Remove 'View' link in CPT view
116
+ }
117
+ }
118
+
119
+ public function sdm_admin_scripts() {
120
+
121
+ global $current_screen, $post;
122
+
123
+ if (is_admin() && $current_screen->post_type == 'sdm_downloads' && $current_screen->base == 'post') {
124
+
125
+ // These scripts are needed for the media upload thickbox
126
+ wp_enqueue_script('media-upload');
127
+ wp_enqueue_script('thickbox');
128
+ wp_register_script('sdm-upload', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_admin_scripts.js', array('jquery', 'media-upload', 'thickbox'));
129
+ wp_enqueue_script('sdm-upload');
130
+
131
+ // Pass postID for thumbnail deletion
132
+ ?>
133
+ <script type="text/javascript">
134
+ var sdm_del_thumb_postid = '<?php echo $post->ID; ?>';
135
+ </script>
136
  <?php
137
+ // Localize langauge strings used in js file
138
+ $sdmTranslations = array(
139
+ 'image_removed' => __('Image Successfully Removed', 'sdm_lang'),
140
+ 'ajax_error' => __('Error with AJAX', 'sdm_lang')
141
+ );
142
+ wp_localize_script('sdm-upload', 'sdm_translations', $sdmTranslations);
143
+ }
144
+
145
+ // Pass admin ajax url
146
+ ?>
147
+ <script type="text/javascript">
148
+ var sdm_admin_ajax_url = {sdm_admin_ajax_url: '<?php echo admin_url('admin-ajax.php?action=ajax'); ?>'};
149
+ var sdm_plugin_url = '<?php echo plugins_url(); ?>';
150
+ var tinymce_langs = {select_download_item: '<?php _e('Please select a Download Item:', 'sdm_lang') ?>', download_title: '<?php _e('Download Title', 'sdm_lang') ?>', include_fancy: '<?php _e('Include Fancy Box', 'sdm_lang') ?>', insert_shortcode: '<?php _e('Insert SDM Shortcode', 'sdm_lang') ?>'};
151
+ </script>
152
+ <?php
153
+ }
154
+
155
+ public function sdm_frontend_scripts() {
156
+
157
+ // Pass language strings to frontend of WP for js usage
158
+ ?>
159
+ <script type="text/javascript">
160
+ var sdm_frontend_translations = {incorrect_password: '<?php _e('Incorrect Password', 'sdm_lang') ?>'};
161
+ </script>
162
+ <?php
163
+ }
164
+
165
+ public function sdm_admin_styles() {
166
+
167
+ wp_enqueue_style('thickbox'); // Needed for media upload thickbox
168
+ wp_enqueue_style('sdm_admin_styles', WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_admin_styles.css'); // Needed for media upload thickbox
169
+ }
170
+
171
+ public function sdm_register_post_type() {
172
+
173
+ //*****
174
+ //***** Create 'sdm_downloads' Custom Post Type
175
+ $labels = array(
176
+ 'name' => __('Downloads', 'sdm_lang'),
177
+ 'singular_name' => __('Downloads', 'sdm_lang'),
178
+ 'add_new' => __('Add New', 'sdm_lang'),
179
+ 'add_new_item' => __('Add New', 'sdm_lang'),
180
+ 'edit_item' => __('Edit Download', 'sdm_lang'),
181
+ 'new_item' => __('New Download', 'sdm_lang'),
182
+ 'all_items' => __('Downloads', 'sdm_lang'),
183
+ 'view_item' => __('View Download', 'sdm_lang'),
184
+ 'search_items' => __('Search Downloads', 'sdm_lang'),
185
+ 'not_found' => __('No Downloads found', 'sdm_lang'),
186
+ 'not_found_in_trash' => __('No Downloads found in Trash', 'sdm_lang'),
187
+ 'parent_item_colon' => __('', 'sdm_lang'),
188
+ 'menu_name' => __('Downloads', 'sdm_lang')
189
+ );
190
+ $args = array(
191
+ 'labels' => $labels,
192
+ 'public' => true,
193
+ 'publicly_queryable' => true,
194
+ 'show_ui' => true,
195
+ 'show_in_menu' => true,
196
+ 'query_var' => true,
197
+ 'rewrite' => array('slug' => 'sdm_downloads'),
198
+ 'capability_type' => 'post',
199
+ 'has_archive' => true,
200
+ 'hierarchical' => false,
201
+ 'menu_position' => null,
202
+ 'menu_icon' => 'dashicons-download',
203
+ 'supports' => array('title')
204
+ );
205
+ register_post_type('sdm_downloads', $args);
206
+ }
207
+
208
+ public function sdm_create_taxonomies() {
209
+
210
+ //*****
211
+ //***** Create CATEGORIES Taxonomy
212
+ $labels_tags = array(
213
+ 'name' => _x('Categories', 'sdm_lang'),
214
+ 'singular_name' => _x('Category', 'sdm_lang'),
215
+ 'search_items' => __('Search Categories', 'sdm_lang'),
216
+ 'all_items' => __('All Categories', 'sdm_lang'),
217
+ 'parent_item' => __('Categories Genre', 'sdm_lang'),
218
+ 'parent_item_colon' => __('Categories Genre:', 'sdm_lang'),
219
+ 'edit_item' => __('Edit Category', 'sdm_lang'),
220
+ 'update_item' => __('Update Category', 'sdm_lang'),
221
+ 'add_new_item' => __('Add New Category', 'sdm_lang'),
222
+ 'new_item_name' => __('New Category', 'sdm_lang'),
223
+ 'menu_name' => __('Categories', 'sdm_lang')
224
+ );
225
+ $args_tags = array(
226
+ 'hierarchical' => true,
227
+ 'labels' => $labels_tags,
228
+ 'show_ui' => true,
229
+ 'query_var' => true,
230
+ 'rewrite' => array('slug' => 'sdm_categories'),
231
+ 'show_admin_column' => true
232
+ );
233
+ register_taxonomy('sdm_categories', array('sdm_downloads'), $args_tags);
234
+
235
+ //*****
236
+ //***** Create TAGS Taxonomy
237
+ $labels_tags = array(
238
+ 'name' => _x('Tags', 'sdm_lang'),
239
+ 'singular_name' => _x('Tag', 'sdm_lang'),
240
+ 'search_items' => __('Search Tags', 'sdm_lang'),
241
+ 'all_items' => __('All Tags', 'sdm_lang'),
242
+ 'parent_item' => __('Tags Genre', 'sdm_lang'),
243
+ 'parent_item_colon' => __('Tags Genre:', 'sdm_lang'),
244
+ 'edit_item' => __('Edit Tag', 'sdm_lang'),
245
+ 'update_item' => __('Update Tag', 'sdm_lang'),
246
+ 'add_new_item' => __('Add New Tag', 'sdm_lang'),
247
+ 'new_item_name' => __('New Tag', 'sdm_lang'),
248
+ 'menu_name' => __('Tags', 'sdm_lang')
249
+ );
250
+ $args_tags = array(
251
+ 'hierarchical' => false,
252
+ 'labels' => $labels_tags,
253
+ 'show_ui' => true,
254
+ 'query_var' => true,
255
+ 'rewrite' => array('slug' => 'sdm_tags'),
256
+ 'show_admin_column' => true
257
+ );
258
+ register_taxonomy('sdm_tags', array('sdm_downloads'), $args_tags);
259
+ }
260
+
261
+ public function sdm_create_menu_pages() {
262
+
263
+ //*****
264
+ //***** If user clicked to download the bulk export log
265
+ if (isset($_GET['download_log'])) {
266
+ global $wpdb;
267
+ $csv_output = '';
268
+ $table = $wpdb->prefix . 'sdm_downloads';
269
+
270
+ $result = mysql_query("SHOW COLUMNS FROM " . $table . "");
271
+
272
+ $i = 0;
273
+ if (mysql_num_rows($result) > 0) {
274
+ while ($row = mysql_fetch_assoc($result)) {
275
+ $csv_output = $csv_output . $row['Field'] . ",";
276
+ $i++;
277
+ }
278
+ }
279
+ $csv_output .= "\n";
280
+
281
+ $values = mysql_query("SELECT * FROM " . $table . "");
282
+ while ($rowr = mysql_fetch_row($values)) {
283
+ for ($j = 0; $j < $i; $j++) {
284
+ $csv_output .= $rowr[$j] . ",";
285
+ }
286
+ $csv_output .= "\n";
287
+ }
288
+
289
+ header("Pragma: public");
290
+ header("Expires: 0");
291
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
292
+ header("Cache-Control: private", false);
293
+ header("Content-Type: application/octet-stream");
294
+ header("Content-Disposition: attachment; filename=\"report.csv\";");
295
+ header("Content-Transfer-Encoding: binary");
296
+
297
+ echo $csv_output;
298
+ exit;
299
+ }
300
+
301
+ //*****
302
+ //***** Create the 'logs' and 'settings' submenu pages
303
+ $sdm_logs_page = add_submenu_page('edit.php?post_type=sdm_downloads', __('Logs', 'sdm_lang'), __('Logs', 'sdm_lang'), 'manage_options', 'logs', 'sdm_create_logs_page');
304
+ $sdm_settings_page = add_submenu_page('edit.php?post_type=sdm_downloads', __('Settings', 'sdm_lang'), __('Settings', 'sdm_lang'), 'manage_options', 'settings', array(&$this, 'sdm_create_settings_page'));
305
+ }
306
+
307
+ public function sdm_create_settings_page() {
308
+ echo '<div class="wrap">';
309
+ echo '<div id="poststuff"><div id="post-body">';
310
+ ?>
311
+ <h2><?php _e('Simple Download Monitor Settings Page', 'sdm_lang') ?></h2>
312
+
313
+ <div style="background: #FFF6D5; border: 1px solid #D1B655; color: #3F2502; padding: 15px 10px">
314
+ <a href="http://www.tipsandtricks-hq.com/development-center" target="_blank"><?php _e('Follow us', 'sdm_lang'); ?></a> <?php _e('on Twitter, Google+ or via Email to stay upto date about the new features of this plugin.', 'sdm_lang'); ?>
315
  </div>
316
+
317
+ <!-- settings page form -->
318
+ <form method="post" action="options.php">
319
+
320
+ <!-- BEGIN ADMIN OPTIONS DIV -->
321
+ <div id="sdm_admin_opts_div" class="sdm_sliding_div_title">
322
+ <div class="sdm_slider_title">
323
+ <?php _e('Admin Options', 'sdm_lang') ?>
324
+ </div>
325
+ <div class="sdm_desc">
326
+ <?php _e("Control various plugin features.", 'sdm_lang') ?>
327
+ </div>
328
+ </div>
329
+ <div id="sliding_div1" class="slidingDiv">
330
  <?php
331
  // This prints out all hidden setting fields
332
+ do_settings_sections('admin_options_section');
333
+ settings_fields('sdm_downloads_options');
 
 
 
 
 
334
 
335
+ submit_button();
336
+ ?>
 
 
337
  </div>
338
+ <!-- END ADMIN OPTIONS DIV -->
339
+
340
+ <!-- BEGIN COLORS DIV -->
341
+ <div id="sdm_color_opts_div" class="sdm_sliding_div_title">
342
+ <div class="sdm_slider_title">
343
+ <?php _e('Color Options', 'sdm_lang') ?>
344
+ </div>
345
+ <div class="sdm_desc">
346
+ <?php _e("Adjust color options", 'sdm_lang') ?>
347
+ </div>
348
  </div>
349
+ <div id="sliding_div2" class="slidingDiv">
 
350
  <?php
351
  // This prints out all hidden setting fields
352
+ do_settings_sections('sdm_colors_section');
353
+ settings_fields('sdm_downloads_options');
354
 
355
+ submit_button();
356
  ?>
357
+ </div>
358
+ <!-- END COLORS OPTIONS DIV -->
359
+
360
+ <!-- End of settings page form -->
361
  </form>
362
+
363
+ <div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
364
+ <p><?php _e('If you need a feature rich and supported plugin for selling your digital items then checkout our', 'sdm_lang'); ?> <a href="http://www.tipsandtricks-hq.com/wordpress-estore-plugin-complete-solution-to-sell-digital-products-from-your-wordpress-blog-securely-1059" target="_blank"><?php _e('WP eStore Plugin', 'sdm_lang'); ?></a>
365
+ </p>
366
+ </div>
367
 
368
  <?php
369
+ echo '</div></div>'; //end of post-stuff
370
+ echo '</div>'; //end of wrap
371
+ }
372
+
373
+ public function sdm_create_upload_metabox() {
374
+
375
+ //*****
376
+ //***** Create metaboxes for the custom post type
377
+ add_meta_box('sdm_description_meta_box', __('Description', 'sdm_lang'), array(&$this, 'display_sdm_description_meta_box'), 'sdm_downloads', 'normal', 'default'
378
+ );
379
+ add_meta_box('sdm_upload_meta_box', __('Upload File', 'sdm_lang'), array(&$this, 'display_sdm_upload_meta_box'), 'sdm_downloads', 'normal', 'default'
380
+ );
381
+ add_meta_box('sdm_thumbnail_meta_box', __('File Thumbnail (Optional)', 'sdm_lang'), array(&$this, 'display_sdm_thumbnail_meta_box'), 'sdm_downloads', 'normal', 'default'
382
+ );
383
+ add_meta_box('sdm_shortcode_meta_box', __('Shortcodes', 'sdm_lang'), array(&$this, 'display_sdm_shortcode_meta_box'), 'sdm_downloads', 'normal', 'default'
384
+ );
385
+ add_meta_box('sdm_stats_meta_box', __('Statistics', 'sdm_lang'), array(&$this, 'display_sdm_stats_meta_box'), 'sdm_downloads', 'normal', 'default'
386
+ );
387
+ }
388
+
389
+ public function display_sdm_description_meta_box($post) { // Description metabox
390
+ _e('Add a description for this download item.', 'sdm_lang');
391
+ echo '<br /><br />';
392
+
393
+ $old_description = get_post_meta($post->ID, 'sdm_description', true);
394
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
  <textarea id="sdm_description" name="sdm_description" style="width:60%;height:40px;"><?php echo $old_description; ?></textarea>
396
  <?php
397
+ wp_nonce_field('sdm_description_box_nonce', 'sdm_description_box_nonce_check');
398
+ }
399
+
400
+ public function display_sdm_upload_meta_box($post) { // File Upload metabox
401
+ $old_upload = get_post_meta($post->ID, 'sdm_upload', true);
402
+ $old_value = isset($old_upload) ? $old_upload : '';
403
+ _e('Click "Select File" to upload (or choose) the file.', 'sdm_lang');
404
+ ?>
 
405
  <br /><br />
406
+ <input id="upload_image_button" type="button" class="button-primary" value="<?php _e('Select File', 'sdm_lang'); ?>" />
407
  <span style="margin-left:40px;"></span>
408
+ <?php _e('File URL:', 'sdm_lang') ?> <input id="sdm_upload" type="text" size="70" name="sdm_upload" value="<?php echo $old_value; ?>" />
409
  <?php
410
+ wp_nonce_field('sdm_upload_box_nonce', 'sdm_upload_box_nonce_check');
411
+ }
412
+
413
+ public function display_sdm_thumbnail_meta_box($post) { // Thumbnail upload metabox
414
+ $old_thumbnail = get_post_meta($post->ID, 'sdm_upload_thumbnail', true);
415
+ $old_value = isset($old_thumbnail) ? $old_thumbnail : '';
416
+ _e('Click "Select Image" to upload (or choose) the file thumbnail image. This thumbnail image will be used to create a fancy file download box if you want to use it.', 'sdm_lang');
417
+ echo '<br />';
418
+ _e('Recommended image size is 75px by 75px.', 'sdm_lang');
419
+ ?>
 
420
  <br /><br />
421
+ <input id="upload_thumbnail_button" type="button" class="button-primary" value="<?php _e('Select Image', 'sdm_lang'); ?>" />
422
+ <input id="remove_thumbnail_button" type="button" class="button" value="<?php _e('Remove Image', 'sdm_lang'); ?>" />
423
  <span style="margin-left:40px;"></span>
424
+ <input id="sdm_upload_thumbnail" type="hidden" size="70" name="sdm_upload_thumbnail" value="<?php echo $old_value; ?>" />
425
  <span id="sdm_get_thumb">
426
+ <?php
427
+ if ($old_value != '') {
428
+ ?><img id="sdm_thumbnail_image" src="<?php echo $old_value; ?>" style="width:75px;height:75px;" />
429
  <?php
430
+ }
431
+ ?></span><?php
432
+ wp_nonce_field('sdm_thumbnail_box_nonce', 'sdm_thumbnail_box_nonce_check');
433
+ }
434
+
435
+ public function display_sdm_shortcode_meta_box($post) { // Shortcode metabox
436
+ _e('This is the shortcode which can used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter to add this shortcode to a post or page.', 'sdm_lang');
437
+ echo '<br />';
438
+ echo '[sdm_download id="' . $post->ID . '" fancy="0"]';
439
+ echo '<br /><br />';
440
+
441
+ _e('This shortcode may be used as a download counter.', 'sdm_lang');
442
+ echo '<br />';
443
+ echo '[sdm_download_counter id="' . $post->ID . '"]';
444
+ }
445
+
446
+ public function display_sdm_stats_meta_box($post) { // Stats metabox
447
+ _e('These are the statistics for this download item.', 'sdm_lang');
448
+ echo '<br /><br />';
449
+
450
+ global $wpdb;
451
+ $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post->ID));
452
+ _e('Number of Downloads:', 'sdm_lang');
453
+ echo ' ' . $wpdb->num_rows;
454
+ }
455
+
456
+ public function sdm_save_description_meta_data($post_id) { // Save Description metabox
457
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
458
+ return;
459
+ if (!isset($_POST['sdm_description_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_description_box_nonce_check'], 'sdm_description_box_nonce'))
460
+ return;
461
+
462
+ if (isset($_POST['sdm_description'])) {
463
+ update_post_meta($post_id, 'sdm_description', $_POST['sdm_description']);
464
+ }
465
+ }
466
+
467
+ public function sdm_save_upload_meta_data($post_id) { // Save File Upload metabox
468
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
469
+ return;
470
+ if (!isset($_POST['sdm_upload_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_upload_box_nonce_check'], 'sdm_upload_box_nonce'))
471
+ return;
472
+
473
+ if (isset($_POST['sdm_upload'])) {
474
+ update_post_meta($post_id, 'sdm_upload', $_POST['sdm_upload']);
475
+ }
476
+ }
477
+
478
+ public function sdm_save_thumbnail_meta_data($post_id) { // Save Thumbnail Upload metabox
479
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
480
+ return;
481
+ if (!isset($_POST['sdm_thumbnail_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_thumbnail_box_nonce_check'], 'sdm_thumbnail_box_nonce'))
482
+ return;
483
+
484
+ if (isset($_POST['sdm_upload_thumbnail'])) {
485
+ update_post_meta($post_id, 'sdm_upload_thumbnail', $_POST['sdm_upload_thumbnail']);
486
+ }
487
+ }
488
+
489
+ public function sdm_remove_view_link_cpt($action, $post) {
490
+
491
+ // Only execute on SDM CPT posts page
492
+ if ($post->post_type == 'sdm_downloads') {
493
+ unset($action['view']);
494
+ }
495
+
496
  return $action;
497
+ }
498
+
499
+ public function sdm_register_options() {
500
+
501
+ register_setting('sdm_downloads_options', 'sdm_downloads_options');
502
+ add_settings_section('admin_options', __('Admin Options', 'sdm_lang'), array($this, 'admin_options_cb'), 'admin_options_section');
503
+ add_settings_section('sdm_colors', __('Colors', 'sdm_lang'), array($this, 'sdm_colors_cb'), 'sdm_colors_section');
504
+
505
+ add_settings_field('admin_tinymce_button', __('Remove Tinymce Button', 'sdm_lang'), array($this, 'admin_tinymce_button_cb'), 'admin_options_section', 'admin_options');
506
+ add_settings_field('download_button_color', __('Download Button Color', 'sdm_lang'), array($this, 'download_button_color_cb'), 'sdm_colors_section', 'sdm_colors');
507
+ }
508
+
509
+ public function admin_options_cb() {
510
+ _e('Admin options settings', 'sdm_lang');
511
+ }
512
+
513
+ public function sdm_colors_cb() {
514
+ _e('Front End colors settings', 'sdm_lang');
515
+ }
516
+
517
+ public function admin_tinymce_button_cb() {
518
+ $main_opts = get_option('sdm_downloads_options');
519
+ echo '<input name="sdm_downloads_options[admin_tinymce_button]" id="admin_tinymce_button" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked(1, isset($main_opts['admin_tinymce_button']), false) . ' /> ';
520
+ _e('Removes the SDM Downloads button from the WP content editor.', 'sdm_lang');
521
+ }
522
+
523
+ public function download_button_color_cb() {
524
+ $main_opts = get_option('sdm_downloads_options');
525
+ $color_opt = $main_opts['download_button_color'];
526
+ $color_opts = array(__('Green', 'sdm_lang'), __('Blue', 'sdm_lang'), __('Purple', 'sdm_lang'), __('Teal', 'sdm_lang'), __('Dark Blue', 'sdm_lang'), __('Black', 'sdm_lang'), __('Grey', 'sdm_lang'), __('Pink', 'sdm_lang'), __('Orange', 'sdm_lang'), __('White', 'sdm_lang'));
527
+ echo '<select name="sdm_downloads_options[download_button_color]" id="download_button_color" class="sdm_opts_ajax_dropdowns">';
528
+ if (isset($color_opt)) {
529
+ echo '<option value="' . $color_opt . '" selected="selected">' . $color_opt . ' (' . __('current', 'sdm_lang') . ')</option>';
530
+ }
531
+ foreach ($color_opts as $color) {
532
+ echo '<option value="' . $color . '" ' . $sel_color . '>' . $color . '</option>';
533
+ }
534
+ echo '</select> ';
535
+ _e('Adjusts the color of the "Download Now" button.', 'sdm_lang');
536
+ }
537
+
538
  }
539
+
540
  $simpleDownloadManager = new simpleDownloadManager();
541
 
542
  /*
543
+ * *
544
+ * * Logs Page
545
+ * *
546
+ */
547
  //*****
548
  //***** Check WP_List_Table exists
549
+ if (!class_exists('WP_List_Table')) {
550
  require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
551
  }
552
 
553
  //*****
554
  //***** Define our new Table
555
  class sdm_List_Table extends WP_List_Table {
556
+
557
+ function __construct() {
558
+
 
559
  global $status, $page;
560
+
561
  //Set parent defaults
562
+ parent::__construct(array(
563
+ 'singular' => __('Download', 'sdm_lang'), //singular name of the listed records
564
+ 'plural' => __('Downloads', 'sdm_lang'), //plural name of the listed records
565
+ 'ajax' => false //does this table support ajax?
566
+ ));
 
567
  }
568
+
569
+ function column_default($item, $column_name) {
570
+
571
+ switch ($column_name) {
572
  case 'URL':
573
  case 'visitor_ip':
574
  case 'date':
575
  return $item[$column_name];
576
+ case 'visitor_country':
577
+ return $item[$column_name];
578
  default:
579
+ return print_r($item, true); //Show the whole array for troubleshooting purposes
580
  }
581
  }
582
+
583
+ function column_title($item) {
584
+
585
  //Build row actions
586
  $actions = array(
587
+ 'edit' => sprintf('<a href="' . admin_url('post.php?post=' . $item['ID'] . '&action=edit') . '">' . __('Edit', 'sdm_lang') . '</a>'),
588
+ 'delete' => sprintf('<a href="?post_type=sdm_downloads&page=%s&action=%s&download=%s&datetime=%s">' . __('Delete', 'sdm_lang') . '</a>', $_REQUEST['page'], 'delete', $item['ID'], $item['date'])
589
  );
590
+
591
  //Return the title contents
592
  return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
593
+ /* $1%s */ $item['title'],
594
+ /* $2%s */ $item['ID'],
595
+ /* $3%s */ $this->row_actions($actions)
596
  );
597
  }
598
+
599
+ function column_cb($item) {
600
+
601
  return sprintf(
602
+ '<input type="checkbox" name="%1$s[]" value="%2$s" />',
603
+ /* $1%s */ $this->_args['singular'], //Let's simply repurpose the table's singular label ("Download")
604
+ /* $2%s */ $item['ID'] . '|' . $item['date'] //The value of the checkbox should be the record's id
605
  );
606
  }
607
+
608
+ function get_columns() {
609
+
610
  $columns = array(
611
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
612
+ 'title' => __('Title', 'sdm_lang'),
613
+ 'URL' => __('File', 'sdm_lang'),
614
+ 'visitor_ip' => __('Visitor IP', 'sdm_lang'),
615
+ 'date' => __('Date', 'sdm_lang'),
616
+ 'visitor_country' => __('Country', 'sdm_lang')
617
  );
618
  return $columns;
619
  }
620
+
621
  function get_sortable_columns() {
622
+
623
  $sortable_columns = array(
624
+ 'title' => array('title', false), //true means it's already sorted
625
+ 'URL' => array('URL', false),
626
+ 'visitor_ip' => array('visitor_ip', false),
627
+ 'date' => array('date', false),
628
+ 'visitor_country' => array('visitor_country', false)
629
  );
630
  return $sortable_columns;
631
  }
632
+
633
  function get_bulk_actions() {
634
+
635
  $actions = array();
636
+ $actions['delete2'] = __('Delete Permanently', 'sdm_lang');
637
+ $actions['export_all'] = __('Export All as Excel', 'sdm_lang');
638
  //$actions['export-selected'] = __( 'Export Selected', 'sdm_lang' );
639
 
640
  return $actions;
641
  }
642
+
643
  function process_bulk_action() {
 
 
 
644
 
645
+ // security check!
646
+ if (isset($_POST['_wpnonce']) && !empty($_POST['_wpnonce'])) {
647
 
648
+ $nonce = filter_input(INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING);
649
+ $action = 'bulk-' . $this->_args['plural'];
650
 
651
+ if (!wp_verify_nonce($nonce, $action))
652
+ wp_die(__('Nope! Security check failed!', 'sdm_lang'));
653
  }
654
 
655
  $action = $this->current_action();
656
+
657
+ // If bulk 'Export All' was clicked
658
+ if ('export_all' === $this->current_action()) {
659
+
660
+ echo '<div id="message" class="updated"><p><strong><a id="sdm_download_export" href="?post_type=sdm_downloads&page=logs&download_log">' . __('Download Export File', 'sdm_lang') . '</a></strong></p></div>';
661
+ }
662
+
663
+ // if bulk 'Delete Permanently' was clicked
664
+ if ('delete2' === $this->current_action()) {
665
+
666
+ if (!isset($_POST['download']) || $_POST['download'] == null) {
667
+ echo '<div id="message" class="updated fade"><p><strong>' . __('No entries were selected.', 'sdm_lang') . '</strong></p><p><em>' . __('Click to Dismiss', 'sdm_lang') . '</em></p></div>';
668
+ return;
669
+ }
670
+
671
+ foreach ($_POST['download'] as $item) {
672
+ $str_tok_id = substr($item, 0, strpos($item, '|'));
673
+ $str_tok_datetime = substr($item, strpos($item, '|') + 1);
674
+
675
+ global $wpdb;
676
+ $del_row = $wpdb->query(
677
+ 'DELETE FROM ' . $wpdb->prefix . 'sdm_downloads
678
+ WHERE post_id = "' . $str_tok_id . '"
679
+ AND date_time = "' . $str_tok_datetime . '"'
680
+ );
681
+ }
682
+ if ($del_row) {
683
+ echo '<div id="message" class="updated fade"><p><strong>' . __('Entries Deleted!', 'sdm_lang') . '</strong></p><p><em>' . __('Click to Dismiss', 'sdm_lang') . '</em></p></div>';
684
+ } else {
685
+ echo '<div id="message" class="updated fade"><p><strong>' . __('Error', 'sdm_lang') . '</strong></p><p><em>' . __('Click to Dismiss', 'sdm_lang') . '</em></p></div>';
686
+ }
687
+ }
688
+
689
+ // If single entry 'Delete' was clicked
690
+ if ('delete' === $this->current_action()) {
691
+
692
+ $item_id = isset($_GET['download']) ? strtok($_GET['download'], '|') : '';
693
+ $item_datetime = isset($_GET['datetime']) ? $_GET['datetime'] : '';
694
+
695
+ global $wpdb;
696
+ $del_row = $wpdb->query(
697
+ 'DELETE FROM ' . $wpdb->prefix . 'sdm_downloads
698
+ WHERE post_id = "' . $item_id . '"
699
+ AND date_time = "' . $item_datetime . '"'
700
+ );
701
+ if ($del_row) {
702
+ echo '<div id="message" class="updated fade"><p><strong>' . __('Entry Deleted!', 'sdm_lang') . '</strong></p><p><em>' . __('Click to Dismiss', 'sdm_lang') . '</em></p></div>';
703
+ } else {
704
+ echo '<div id="message" class="updated fade"><p><strong>' . __('Error', 'sdm_lang') . '</strong></p><p><em>' . __('Click to Dismiss', 'sdm_lang') . '</em></p></div>';
705
+ }
 
 
706
  }
 
707
  }
708
+
709
  function prepare_items() {
710
+
711
  global $wpdb; //This is used only if making any database queries
712
  $per_page = 10;
713
  $columns = $this->get_columns();
714
  $hidden = array();
715
  $sortable = $this->get_sortable_columns();
716
+
717
+
718
  $this->_column_headers = array($columns, $hidden, $sortable);
719
  $this->process_bulk_action();
720
+
721
  //$data = $this->example_data;
722
+
723
+ function usort_reorder($a, $b) {
724
  $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'title'; //If no sort, default to title
725
  $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
726
  $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
727
+ return ($order === 'asc') ? $result : -$result; //Send final sort direction to usort
728
  }
729
+
730
+ $data_results = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads');
731
+ $data = array();
732
+ foreach ($data_results as $data_result) {
733
+ $data[] = array('ID' => $data_result->post_id, 'title' => $data_result->post_title, 'URL' => $data_result->file_url, 'visitor_ip' => $data_result->visitor_ip, 'date' => $data_result->date_time, 'visitor_country' => $data_result->visitor_country);
734
+ }
735
+
736
+
737
  usort($data, 'usort_reorder');
738
  $current_page = $this->get_pagenum();
739
  $total_items = count($data);
740
+ $data = array_slice($data, (($current_page - 1) * $per_page), $per_page);
741
+
742
  $this->items = $data;
743
+ $this->set_pagination_args(array(
744
+ 'total_items' => $total_items, //WE have to calculate the total number of items
745
+ 'per_page' => $per_page, //WE have to determine how many items to show on a page
746
+ 'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages
747
+ ));
748
  }
749
+
750
  }
751
+
752
+ function sdm_create_logs_page() {
753
+
754
  //Create an instance of our package class...
755
  $sdmListTable = new sdm_List_Table();
756
  //Fetch, prepare, sort, and filter our data...
757
  $sdmListTable->prepare_items();
 
758
  ?>
759
  <div class="wrap">
760
+
761
  <div id="icon-users" class="icon32"><br/></div>
762
  <h2><?php _e('Download Logs', 'sdm_lang'); ?></h2>
763
+
764
  <div style="background:#ECECEC;border:1px solid #CCC;padding:0 10px;margin-top:5px;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;">
765
  <p><?php _e('This page lists all tracked downloads.', 'sdm_lang'); ?></p>
766
  </div>
767
+
768
  <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
769
  <form id="sdm_downloads-filter" method="post">
770
  <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
771
  <!-- Now we can render the completed list table -->
772
+ <?php $sdmListTable->display() ?>
773
  </form>
774
+
775
  </div>
776
  <script type="text/javascript">
777
+ jQuery(document).ready(function($) {
778
+ $('.fade').click(function() {
779
+ $(this).fadeOut('slow');
780
+ });
781
+ });
782
+ </script>
783
  <?php
784
  }
785
 
786
+ function sdm_get_password_entry_form($id) {
787
+ $data = __('Enter Password to Download:', 'sdm_lang');
788
+ $data .= '<form method="post">';
789
+ $data .= '<input type="password" class="pass_text" value="" /> ';
790
+ $data .= '<input type="button" class="pass_sumbit" value="' . __('Submit', 'sdm_lang') . '" />';
791
+ $data .= '<input type="hidden" value="' . $id . '" />';
792
+ $data .= '</form>';
793
+ return $data;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
794
  }
795
 
796
+ /*
797
+ * * Register scripts for front-end posts/pages
798
+ */
799
+ add_action('wp_enqueue_scripts', 'sdm_wp_scripts');
 
 
 
 
 
 
800
 
801
+ function sdm_wp_scripts() {
802
+
803
+ wp_enqueue_style('sdm-styles', WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_wp_styles.css');
804
+ wp_register_script('sdm-scripts', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_wp_scripts.js', array('jquery'));
805
+ wp_enqueue_script('sdm-scripts');
806
+
807
+ // Localize ajax script for frontend
808
+ wp_localize_script('sdm-scripts', 'sdm_ajax_script', array('ajaxurl' => admin_url('admin-ajax.php')));
 
 
 
 
 
 
809
  }
810
 
811
+ function handle_sdm_download_via_direct_post() {
812
+ if (isset($_REQUEST['smd_process_download']) && $_REQUEST['smd_process_download'] == '1') {
813
+ $download_id = strip_tags($_REQUEST['download_id']);
814
+ $download_title = get_the_title($download_id);
815
+ $download_link = get_post_meta($download_id, 'sdm_upload', true);
816
+ $ipaddress = $_SERVER["REMOTE_ADDR"];
817
+ $date_time = current_time('mysql');
818
+ $visitor_country = sdm_ip_info('Visitor', 'Country');
819
 
820
+ global $wpdb;
821
+ $table = $wpdb->prefix . 'sdm_downloads';
822
+ $data = array(
823
+ 'post_id' => $download_id,
824
+ 'post_title' => $download_title,
825
+ 'file_url' => $download_link,
826
+ 'visitor_ip' => $ipaddress,
827
+ 'date_time' => $date_time,
828
+ 'visitor_country' => $visitor_country
829
+ );
830
 
831
+ $insert_table = $wpdb->insert($table, $data);
832
+
833
+ if ($insert_table) {//Download request was logged successfully
834
+ sdm_redirect_to_url($download_link);
835
+ } else {//Failed to log the download request
836
+ wp_die(__('Error! Failed to log the download request in the database table', 'sdm_lang'));
837
+ }
838
+ exit;
839
+ }
 
 
 
840
  }
841
 
842
+ function sdm_redirect_to_url($url, $delay = '0', $exit = '1') {
843
+ if (empty($url)) {
844
+ echo '<strong>';
845
+ _e('Error! The URL value is empty. Please specify a correct URL value to redirect to!', 'sdm_lang');
846
+ echo '</strong>';
847
+ exit;
848
+ }
849
+ if (!headers_sent()) {
850
+ header('Location: ' . $url);
851
+ } else {
852
+ echo '<meta http-equiv="refresh" content="' . $delay . ';url=' . $url . '" />';
853
+ }
854
+ if ($exit == '1') {//exit
855
+ exit;
856
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
857
  }
858
 
859
  // Tinymce Button Populate Post ID's
860
+ add_action('wp_ajax_nopriv_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call');
861
+ add_action('wp_ajax_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call');
862
+
863
  function sdm_tiny_get_post_ids_ajax_call() {
864
+
865
+ $args = array(
866
+ 'post_type' => 'sdm_downloads',
867
+ );
868
+ $loop = new WP_Query($args);
869
+ $test = '';
870
+ foreach ($loop->posts as $loop_post) {
871
+ //$test .= $loop_post->ID.'|'.$loop_post->post_title.'_';
872
+ $test[] = array('post_id' => $loop_post->ID, 'post_title' => $loop_post->post_title);
873
+ }
874
+
875
+ $response = json_encode(array('success' => true, 'test' => $test));
876
+
877
+ header('Content-Type: application/json');
878
+ echo $response;
879
+ exit;
880
  }
881
+
882
  // Remove Thumbnail Image
883
+ add_action('wp_ajax_nopriv_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call');
884
+ add_action('wp_ajax_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call');
885
+
886
  function sdm_remove_thumbnail_image_ajax_call() {
887
+
888
+ $post_id = $_POST['post_id_del'];
889
+ $success = delete_post_meta($post_id, 'sdm_upload_thumbnail');
890
+ if ($success) {
891
+ $response = json_encode(array('success' => true));
892
+ }
893
+
894
+ header('Content-Type: application/json');
895
+ echo $response;
896
+ exit;
897
  }
898
+
899
  // Check download password
900
+ add_action('wp_ajax_nopriv_sdm_check_pass', 'sdm_check_pass_ajax_call');
901
+ add_action('wp_ajax_sdm_check_pass', 'sdm_check_pass_ajax_call');
902
+
903
  function sdm_check_pass_ajax_call() {
904
+
905
+ $button_id = $_POST['button_id']; // Get button cpt id
906
+ $pass_val = $_POST['pass_val']; // Get password attempt
907
+ $success = '';
908
+ $download_link = '';
909
+
910
+ // Get post object
911
+ $post_object = get_post($button_id);
912
+ // Get post password
913
+ $post_pass = $post_object->post_password;
914
+
915
+ // Check if password is a match
916
+ if ($post_pass != $pass_val) { // Match is a failure
917
+ $success = 'no'; // Pass back to ajax
918
+ } else { // Match is a success
919
+ $success = 'yes'; // Pass back to ajax
920
+
921
+ $download_id = $button_id;
922
+ $download_title = get_the_title($download_id);
923
+ $download_link = get_post_meta($download_id, 'sdm_upload', true);
924
+ $ipaddress = $_SERVER["REMOTE_ADDR"];
925
+ $date_time = current_time('mysql');
926
+ $visitor_country = sdm_ip_info('Visitor', 'Country');
927
+
928
+ global $wpdb;
929
+ $table = $wpdb->prefix . 'sdm_downloads';
930
+ $data = array(
931
+ 'post_id' => $download_id,
932
+ 'post_title' => $download_title,
933
+ 'file_url' => $download_link,
934
+ 'visitor_ip' => $ipaddress,
935
+ 'date_time' => $date_time,
936
+ 'visitor_country' => $visitor_country
937
+ );
938
+
939
+ $insert_table = $wpdb->insert($table, $data);
940
+ }
941
+
942
+ // Generate ajax response
943
+ $response = json_encode(array('success' => $success, 'url' => $download_link));
944
+ header('Content-Type: application/json');
945
+ echo $response;
946
+ exit;
947
+ }
948
+
949
+ // Populate category tree
950
+ add_action('wp_ajax_nopriv_sdm_pop_cats', 'sdm_pop_cats_ajax_call');
951
+ add_action('wp_ajax_sdm_pop_cats', 'sdm_pop_cats_ajax_call');
952
+
953
+ function sdm_pop_cats_ajax_call() {
954
+
955
+ $cat_slug = $_POST['cat_slug']; // Get button cpt slug
956
+ $parent_id = $_POST['parent_id']; // Get button cpt id
957
+ // Query custom posts based on taxonomy slug
958
+ $posts = query_posts(array(
959
+ 'post_type' => 'sdm_downloads',
960
+ //'showposts' => -1,
961
+ 'tax_query' => array(
962
+ array(
963
+ 'taxonomy' => 'sdm_categories',
964
+ 'terms' => $cat_slug,
965
+ 'field' => 'slug',
966
+ 'include_children' => 0
967
+ )
968
+ ),
969
+ 'orderby' => 'title',
970
+ 'order' => 'ASC')
971
+ );
972
+
973
+ // Loop results
974
+ foreach ($posts as $post) {
975
+
976
+ // Create array of variables to pass to js
977
+ $final_array[] = array('id' => $post->ID, 'permalink' => get_permalink($post->ID), 'title' => $post->post_title);
978
+ }
979
+
980
+ // Generate ajax response
981
+ $response = json_encode(array('final_array' => $final_array));
982
+ header('Content-Type: application/json');
983
+ echo $response;
984
+ exit;
985
  }
986
 
987
  /*
988
+ * * Setup Sortable Columns
989
+ */
990
+ add_filter('manage_edit-sdm_downloads_columns', 'sdm_create_columns'); // Define columns
991
+ add_filter('manage_edit-sdm_downloads_sortable_columns', 'sdm_downloads_sortable'); // Make sortable
992
+ add_action('manage_sdm_downloads_posts_custom_column', 'sdm_downloads_columns_content', 10, 2); // Populate new columns
993
+
994
+ function sdm_create_columns($cols) {
995
+
996
+ unset($cols['title']);
997
+ unset($cols['taxonomy-sdm_tags']);
998
+ unset($cols['taxonomy-sdm_categories']);
999
+ unset($cols['date']);
1000
+ unset($cols['visitor_country']);
1001
+
1002
+ $cols['sdm_downloads_thumbnail'] = __('Image', 'sdm_lang');
1003
+ $cols['title'] = __('Title', 'sdm_lang');
1004
+ $cols['sdm_downloads_id'] = __('ID', 'sdm_lang');
1005
+ $cols['sdm_downloads_file'] = __('File', 'sdm_lang');
1006
+ $cols['taxonomy-sdm_categories'] = __('Categories', 'sdm_lang');
1007
+ $cols['taxonomy-sdm_tags'] = __('Tags', 'sdm_lang');
1008
+ $cols['sdm_downloads_count'] = __('Downloads', 'sdm_lang');
1009
+ $cols['date'] = __('Date Posted', 'sdm_lang');
1010
+ $cols['visitor_country'] = __('Visitor Country', 'sdm_lang');
1011
+ return $cols;
1012
  }
1013
 
1014
+ function sdm_downloads_sortable($cols) {
1015
+
1016
+ $cols['sdm_downloads_id'] = 'sdm_downloads_id';
1017
+ $cols['sdm_downloads_file'] = 'sdm_downloads_file';
1018
+ $cols['sdm_downloads_count'] = 'sdm_downloads_count';
1019
+ $cols['taxonomy-sdm_categories'] = 'taxonomy-sdm_categories';
1020
+ $cols['taxonomy-sdm_tags'] = 'taxonomy-sdm_tags';
1021
+ return $cols;
1022
  }
1023
 
1024
+ function sdm_downloads_columns_content($column_name, $post_ID) {
1025
+
1026
+ if ($column_name == 'sdm_downloads_thumbnail') {
1027
+ $old_thumbnail = get_post_meta($post_ID, 'sdm_upload_thumbnail', true);
1028
+ //$old_value = isset($old_thumbnail) ? $old_thumbnail : '';
1029
+ if ($old_thumbnail) {
1030
+ echo '<p class="sdm_downloads_count"><img src="' . $old_thumbnail . '" style="width:50px;height:50px;" /></p>';
1031
+ }
1032
+ }
1033
+ if ($column_name == 'sdm_downloads_id') {
1034
+ echo '<p class="sdm_downloads_postid">' . $post_ID . '</p>';
1035
+ }
1036
+ if ($column_name == 'sdm_downloads_file') {
1037
+ $old_file = get_post_meta($post_ID, 'sdm_upload', true);
1038
+ $file = isset($old_file) ? $old_file : '--';
1039
+ echo '<p class="sdm_downloads_file">' . $file . '</p>';
1040
+ }
1041
+ if ($column_name == 'sdm_downloads_count') {
1042
+ global $wpdb;
1043
+ $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post_ID));
1044
+ echo '<p class="sdm_downloads_count">' . $wpdb->num_rows . '</p>';
1045
+ }
1046
  }
1047
+
1048
  // Adjust admin column widths
1049
  add_action('admin_head', 'sdm_admin_column_width'); // Adjust column width in admin panel
1050
+
1051
  function sdm_admin_column_width() {
1052
+
1053
  echo '<style type="text/css">';
1054
  echo '.column-sdm_downloads_thumbnail { width:75px !important; overflow:hidden }';
1055
  echo '.column-sdm_downloads_id { width:100px !important; overflow:hidden }';
1056
  echo '.column-taxonomy-sdm_categories { width:200px !important; overflow:hidden }';
1057
  echo '.column-taxonomy-sdm_tags { width:200px !important; overflow:hidden }';
1058
  echo '</style>';
1059
+ }
1060
 
1061
  /*
1062
+ * * Register Tinymce Button
1063
+ */
1064
 
1065
  // First check if option is checked to disable tinymce button
1066
  $main_option = get_option('sdm_downloads_options');
1067
  $tiny_button_option = isset($main_option['admin_tinymce_button']);
1068
+ if ($tiny_button_option != true) {
1069
+
1070
+ // Okay.. we're good. Add the button.
1071
+ add_action('init', 'sdm_downloads_tinymce_button');
1072
+
1073
+ function sdm_downloads_tinymce_button() {
1074
+
1075
+ add_filter('mce_external_plugins', 'sdm_downloads_add_button');
1076
+ add_filter('mce_buttons', 'sdm_downloads_register_button');
1077
+ }
1078
+
1079
+ function sdm_downloads_add_button($plugin_array) {
1080
+
1081
+ $plugin_array['sdm_downloads'] = WP_SIMPLE_DL_MONITOR_URL . '/tinymce/sdm_editor_plugin.js';
1082
+ return $plugin_array;
1083
+ }
1084
+
1085
+ function sdm_downloads_register_button($buttons) {
1086
+
1087
+ //array_push( $buttons, 'sdm_downloads' );
1088
+ $buttons[] = 'sdm_downloads';
1089
+ return $buttons;
1090
+ }
1091
+
1092
  }
1093
+
1094
+ // Helper function to get visitor country (or other info)
1095
+ function sdm_ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
1096
+ $output = NULL;
1097
+ if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {
1098
+ $ip = $_SERVER["REMOTE_ADDR"];
1099
+ if ($deep_detect) {
1100
+ if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
1101
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
1102
+ if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
1103
+ $ip = $_SERVER['HTTP_CLIENT_IP'];
1104
+ }
1105
+ }
1106
+ $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose)));
1107
+ $support = array("country", "countrycode", "state", "region", "city", "location", "address");
1108
+ $continents = array(
1109
+ "AF" => "Africa",
1110
+ "AN" => "Antarctica",
1111
+ "AS" => "Asia",
1112
+ "EU" => "Europe",
1113
+ "OC" => "Australia (Oceania)",
1114
+ "NA" => "North America",
1115
+ "SA" => "South America"
1116
+ );
1117
+ if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) {
1118
+ $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
1119
+ if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) {
1120
+ switch ($purpose) {
1121
+ case "location":
1122
+ $output = array(
1123
+ "city" => @$ipdat->geoplugin_city,
1124
+ "state" => @$ipdat->geoplugin_regionName,
1125
+ "country" => @$ipdat->geoplugin_countryName,
1126
+ "country_code" => @$ipdat->geoplugin_countryCode,
1127
+ "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)],
1128
+ "continent_code" => @$ipdat->geoplugin_continentCode
1129
+ );
1130
+ break;
1131
+ case "address":
1132
+ $address = array($ipdat->geoplugin_countryName);
1133
+ if (@strlen($ipdat->geoplugin_regionName) >= 1)
1134
+ $address[] = $ipdat->geoplugin_regionName;
1135
+ if (@strlen($ipdat->geoplugin_city) >= 1)
1136
+ $address[] = $ipdat->geoplugin_city;
1137
+ $output = implode(", ", array_reverse($address));
1138
+ break;
1139
+ case "city":
1140
+ $output = @$ipdat->geoplugin_city;
1141
+ break;
1142
+ case "state":
1143
+ $output = @$ipdat->geoplugin_regionName;
1144
+ break;
1145
+ case "region":
1146
+ $output = @$ipdat->geoplugin_regionName;
1147
+ break;
1148
+ case "country":
1149
+ $output = @$ipdat->geoplugin_countryName;
1150
+ break;
1151
+ case "countrycode":
1152
+ $output = @$ipdat->geoplugin_countryCode;
1153
+ break;
1154
+ }
1155
+ }
1156
+ }
1157
+ return $output;
1158
+ }
readme.txt CHANGED
@@ -1,19 +1,23 @@
1
  === Simple Download Monitor ===
2
  Contributors: Tips and Tricks HQ, Ruhul Amin, josh401
3
  Donate link: http://www.tipsandtricks-hq.com
4
- Tags: download, downloads, count, counter, tracker, tracking, hits, logging, monitor, manager, files, media, digital, download monitor, download manager, file manager, protect downloads,
5
  Requires at least: 3.0
6
- Tested up to: 3.8.1
7
- Stable tag: 2.5
8
  License: GPLv2 or later
9
 
10
  Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
11
 
12
  == Description ==
13
 
14
- I developed the Simple Download Monitor plugin because I wanted to monitor the number of downloads of my files.
15
 
16
- This plugin is very useful for managing and tracking your digital file download counts. You can password protect your downloadable files too.
 
 
 
 
17
 
18
  You can configure downloadable files from your WordPress admin dashboard via an elegant user interface. Then allow your visitors to download the files and this plugin will monitor which files get downloaded how many times.
19
 
@@ -37,13 +41,16 @@ http://www.youtube.com/watch?v=L-mXbs7kp0s
37
  * Option to use a nice looking template to show your download now buttons.
38
  * Ability to search and sort your downloadable files in the admin dashboard.
39
  * Track the number of downloads for each of your files.
 
40
  * WordPress Shortcode for embedding a download link for a file.
41
  * Tinymce button in the WordPress post/page editor so you can easily add the shortcode.
42
  * Ability to add the download now buttons to your sidebar widget.
43
  * Create password protected download now buttons. Users will only be able to download the file if they enter the correct password
44
  * Shortcode to show the download counter of a file. Use it to show off your file download count.
 
 
45
 
46
- View more usage details on the [download monitor plugin](http://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin) page.
47
 
48
  = Simple Download Monitor Plugin Usage =
49
 
@@ -81,6 +88,8 @@ Example Shortcode Usage:
81
 
82
  You can check the download stats from the "Downloads->Logs" interface. It shows the number of downloads for each files, IP address of the user who downloaded it, date and time of the download.
83
 
 
 
84
  == Installation ==
85
 
86
  1. Go to the Add New plugins screen in your WordPress admin area
@@ -99,12 +108,44 @@ You can pretty much upload all common file types.
99
  = Can I use external file URLs? =
100
  Yes, you can use both local paths and external URLs.
101
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  == Screenshots ==
103
 
104
  For screenshots please visit the [download monitor plugin page](http://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin)
105
 
106
  == Changelog ==
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  = 2.5 =
109
  * Added a new feature to password protect a downloadable file.
110
  * Added a new shortcode to show the download count to your visitors.
1
  === Simple Download Monitor ===
2
  Contributors: Tips and Tricks HQ, Ruhul Amin, josh401
3
  Donate link: http://www.tipsandtricks-hq.com
4
+ Tags: download, downloads, count, counter, tracker, tracking, hits, logging, monitor, manager, files, media, digital, download monitor, download manager, downloadmanager, file manager, protect downloads, password, download category, file tree, ajax,
5
  Requires at least: 3.0
6
+ Tested up to: 3.9
7
+ Stable tag: 2.9
8
  License: GPLv2 or later
9
 
10
  Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
11
 
12
  == Description ==
13
 
14
+ I developed the Simple Download Monitor plugin because I needed a nice way to manage my digital downloads and monitor the number of downloads of my files.
15
 
16
+ This plugin is very useful for managing and tracking your digital file download counts.
17
+
18
+ You can password protect your downloadable files too (visitors will require a password before downloading the file when you use this option).
19
+
20
+ There is an option to show an ajax file tree browser so your visitors can browse all your files and download the ones they want.
21
 
22
  You can configure downloadable files from your WordPress admin dashboard via an elegant user interface. Then allow your visitors to download the files and this plugin will monitor which files get downloaded how many times.
23
 
41
  * Option to use a nice looking template to show your download now buttons.
42
  * Ability to search and sort your downloadable files in the admin dashboard.
43
  * Track the number of downloads for each of your files.
44
+ * Track the visitors country.
45
  * WordPress Shortcode for embedding a download link for a file.
46
  * Tinymce button in the WordPress post/page editor so you can easily add the shortcode.
47
  * Ability to add the download now buttons to your sidebar widget.
48
  * Create password protected download now buttons. Users will only be able to download the file if they enter the correct password
49
  * Shortcode to show the download counter of a file. Use it to show off your file download count.
50
+ * Shortcode to show all the downloads from a particular category.
51
+ * Shortcode to embed a file tree browser for your downloadable files. The file browser is ajax based and it shows the files structured by categories.
52
 
53
+ View more details on the [download monitor plugin](http://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin) page.
54
 
55
  = Simple Download Monitor Plugin Usage =
56
 
88
 
89
  You can check the download stats from the "Downloads->Logs" interface. It shows the number of downloads for each files, IP address of the user who downloaded it, date and time of the download.
90
 
91
+ View more usage instructions on the [Download Monitor Plugin](http://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin) page.
92
+
93
  == Installation ==
94
 
95
  1. Go to the Add New plugins screen in your WordPress admin area
108
  = Can I use external file URLs? =
109
  Yes, you can use both local paths and external URLs.
110
 
111
+ = Can I password protect a downloadable file? =
112
+ Yes.
113
+
114
+ = Can I show the file download counts to my visitors? =
115
+ Yes.
116
+
117
+ = Can I show all downloads from a category? =
118
+ Yes.
119
+
120
+ = Can I show an ajax file tree browser using this plugin? =
121
+ Yes.
122
+
123
  == Screenshots ==
124
 
125
  For screenshots please visit the [download monitor plugin page](http://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin)
126
 
127
  == Changelog ==
128
 
129
+ = 2.9 =
130
+ * Added visitor Country to database table; allowing tracking of each download visitors Country.
131
+ * Visitor Country is also seen in the "Logs" page; can be sorted; and exported.
132
+
133
+ = 2.8 =
134
+ * Added the ability to use shortcodes in the description area of the downloads. For example: you can use the download counter shortcode in the description field to show the current counter to your visitors.
135
+ * Bug-fix for the "show downloads from a category" shortcode. It will now correctly show all items in a download category.
136
+ * Added a better dashicons icon for the downloads menu in the admin dashborad.
137
+
138
+ = 2.7 =
139
+ * Added a new feature to show an ajax file tree browser.
140
+ * Added some missing translation strings in the plugin.
141
+ * Added German language translation. Translation file submitted by Meinhard
142
+ * Changed the password input field to a type of "password"
143
+ * Fixed a minor but that would preven the "view" links from displaying in WordPress posts
144
+
145
+ = 2.6 =
146
+ * Added a new shortcode to show all downloads from a download category.
147
+ * Added a filter to handle the URL of SDM downloads post type.
148
+
149
  = 2.5 =
150
  * Added a new feature to password protect a downloadable file.
151
  * Added a new shortcode to show the download count to your visitors.
sdm-post-type-content-handler.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_filter('the_content', 'filter_sdm_post_type_content');
4
+
5
+ function filter_sdm_post_type_content($content)
6
+ {
7
+ global $post;
8
+ if($post->post_type == "sdm_downloads"){//Handle the content for sdm_downloads type post
9
+ $download_id = $post->ID;
10
+ $args = array('id'=>$download_id, 'fancy'=>'1');
11
+ $content = sdm_create_download_shortcode($args);
12
+ return $content;
13
+ }
14
+
15
+ return $content;
16
+ }
sdm-shortcodes.php ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ ** Register and handle Shortcode
5
+ */
6
+
7
+ function sdm_register_shortcodes() {
8
+ add_shortcode('sdm-download', 'sdm_create_download_shortcode' ); // For download shortcode
9
+ add_shortcode('sdm_download', 'sdm_create_download_shortcode' ); // For download shortcode (underscores)
10
+ add_shortcode('sdm-download-counter', 'sdm_create_counter_shortcode' ); // For counter shortcode
11
+ add_shortcode('sdm_download_counter', 'sdm_create_counter_shortcode' ); // For counter shortcode (underscores)
12
+ add_shortcode('sdm_show_dl_from_category', 'sdm_handle_category_shortcode' ); //For category shortcode
13
+ add_shortcode('sdm_download_categories', 'sdm_download_categories_shortcode' );// Ajax file tree browser
14
+ }
15
+
16
+ // Create Download Shortcode
17
+ function sdm_create_download_shortcode( $atts ) {
18
+
19
+ extract( shortcode_atts( array(
20
+ 'id' => 'id',
21
+ 'fancy' => '0'
22
+ ), $atts ) );
23
+
24
+ // Check to see if the download link cpt is password protected
25
+ $get_cpt_object = get_post($id);
26
+ $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected;
27
+
28
+ // Get CPT thumbnail
29
+ $item_download_thumbnail = get_post_meta( $id, 'sdm_upload_thumbnail', true );
30
+ $isset_download_thumbnail = isset($item_download_thumbnail) && !empty($item_download_thumbnail) ? '<img class="sdm_download_thumbnail_image" src="'.$item_download_thumbnail.'" />' : '';
31
+
32
+ // Get CPT title
33
+ $item_title = get_the_title( $id );
34
+ $isset_item_title = isset($item_title) && !empty($item_title) ? $item_title : '';
35
+
36
+ // Get CPT description
37
+ $item_description = get_post_meta( $id, 'sdm_description', true );
38
+ $isset_item_description = isset($item_description) && !empty($item_description) ? $item_description : '';
39
+ $isset_item_description = do_shortcode($isset_item_description);
40
+
41
+ // Get CPT download link
42
+ $item_link = get_post_meta( $id, 'sdm_upload', true );
43
+ $isset_item_link = isset($item_link) && !empty($item_link) ? $item_link : '';
44
+
45
+ // See if user color option is selected
46
+ $main_opts = get_option('sdm_downloads_options');
47
+ $color_opt = $main_opts['download_button_color'];
48
+ $def_color = isset($color_opt) ? str_replace(' ', '', strtolower($color_opt)) : __('green', 'sdm_lang');
49
+
50
+ //Download counter
51
+ //$dl_counter = sdm_create_counter_shortcode(array('id'=>$id));
52
+
53
+ //Generate the download now button code
54
+ $homepage = get_bloginfo('url');
55
+ $download_url = $homepage. '/?smd_process_download=1&download_id='.$id;
56
+ $download_button_code = '<a href="'.$download_url.'" class="sdm_download '.$def_color.'" title="'.$isset_item_title.'">'.__('Download Now!', 'sdm_lang').'</a>';
57
+
58
+ if($cpt_is_password !== 'no'){//This is a password protected download so replace the download now button with password requirement
59
+ $download_button_code = sdm_get_password_entry_form($id);
60
+ }
61
+ //End of download now button code generation
62
+
63
+ if ($fancy == '0') {
64
+ $data = '<div class="sdm_download_link">'.$download_button_code.'</div>';
65
+ return $data;
66
+ }
67
+
68
+ if ($fancy == '1') {
69
+ // Prepare shortcode
70
+ $data = '<div class="sdm_download_item">';
71
+ $data .= '<div class="sdm_download_item_top">';
72
+ $data .= '<div class="sdm_download_thumbnail">'.$isset_download_thumbnail.'</div>';
73
+ $data .= '<div class="sdm_download_title">'.$isset_item_title.'</div>';
74
+ $data .= '</div>';//End of .sdm_download_item_top
75
+ $data .= '<div style="clear:both;"></div>';
76
+ $data .= '<div class="sdm_download_description">'.$isset_item_description.'</div>';
77
+ $data .= '<div class="sdm_download_link">'.$download_button_code.'</div>';
78
+ $data .= '</div>';
79
+ // Render shortcode
80
+ return $data;
81
+ }
82
+ }
83
+
84
+ // Create Counter Shortcode
85
+ function sdm_create_counter_shortcode( $atts ) {
86
+
87
+ extract( shortcode_atts( array(
88
+ 'id' => 'id'
89
+ ), $atts ) );
90
+
91
+ // Get number of downloads by counting db columns matching postID
92
+ global $wpdb;
93
+ $table = $wpdb->prefix.'sdm_downloads';
94
+ $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$table.' WHERE post_id=%s', $id));
95
+
96
+ // Return result
97
+ return $wpdb->num_rows.' '.__('Downloads','sdm_lang');
98
+ }
99
+
100
+ // Create Category Shortcode
101
+ function sdm_handle_category_shortcode($args){
102
+
103
+ extract( shortcode_atts( array(
104
+ 'category_slug' => '',
105
+ 'category_id' => '',
106
+ 'fancy' => '0'
107
+ ), $args ) );
108
+
109
+ // Define vars
110
+ $field = '';
111
+ $terms = '';
112
+
113
+ // If category slug and category id are empty.. return error
114
+ if(empty($category_slug) && empty($category_id)){
115
+ return '<p style="color: red;">'.__('Error! You must enter a category slug OR a category id with this shortcode. Refer to the documentation for usage instructions.', 'sdm_lang').'</p>';
116
+ }
117
+ // Else if both category slug AND category id are defined... return error
118
+ else if(!empty($category_slug) && !empty($category_id)) {
119
+ return '<p style="color: red;">'.__('Error! Please enter a category slug OR id; not both.', 'sdm_lang').'</p>';
120
+ }
121
+ // Else setup query arguments for category_slug
122
+ else if(!empty($category_slug) && empty($category_id)) {
123
+
124
+ $field = 'slug';
125
+ $terms = $category_slug;
126
+ }
127
+ // Else setup query arguments for category_id
128
+ else if(!empty($category_id) && empty($category_slug)) {
129
+
130
+ $field = 'term_id';
131
+ $terms = $category_id;
132
+ }
133
+
134
+ // Query cpt's based on arguments above
135
+ $get_posts = get_posts(array(
136
+ 'post_type' => 'sdm_downloads',
137
+ 'show_posts' => -1,
138
+ 'posts_per_page' => 9999,
139
+ 'tax_query' => array(
140
+ array(
141
+ 'taxonomy' => 'sdm_categories',
142
+ 'field' => $field,
143
+ 'terms' => $terms
144
+ )
145
+ )
146
+ ));
147
+
148
+ // If no cpt's are found
149
+ if(!$get_posts) {
150
+ return '<p style="color: red;">'.__('There are no download items matching this category criteria.', 'sdm_lang').'</p>';
151
+ }
152
+ // Else iterate cpt's
153
+ else {
154
+
155
+ // Setup download location
156
+ $data = '';
157
+ $homepage = get_bloginfo('url');
158
+
159
+ // See if user color option is selected
160
+ $main_opts = get_option('sdm_downloads_options');
161
+ $color_opt = $main_opts['download_button_color'];
162
+ $def_color = isset($color_opt) ? str_replace(' ', '', strtolower($color_opt)) : __('green', 'sdm_lang');
163
+
164
+ // Iterate cpt's
165
+ foreach ($get_posts as $item) {
166
+
167
+ // Set download location
168
+ $id = $item->ID; // get each cpt ID
169
+ $download_url = $homepage. '/?smd_process_download=1&download_id='.$id;
170
+
171
+ // Get each cpt title
172
+ $item_title = get_the_title( $id );
173
+ $isset_item_title = isset($item_title) && !empty($item_title) ? $item_title : '';
174
+
175
+ // Get CPT thumbnail (for fancy option)
176
+ $item_download_thumbnail = get_post_meta( $id, 'sdm_upload_thumbnail', true );
177
+ $isset_download_thumbnail = isset($item_download_thumbnail) && !empty($item_download_thumbnail) ? '<img class="sdm_download_thumbnail_image" src="'.$item_download_thumbnail.'" />' : '';
178
+
179
+ // Get CPT description (for fancy option)
180
+ $item_description = get_post_meta( $id, 'sdm_description', true );
181
+ $isset_item_description = isset($item_description) && !empty($item_description) ? $item_description : '';
182
+
183
+ // Setup download button code
184
+ $download_button_code = '<a href="'.$download_url.'" class="sdm_download '.$def_color.'" title="'.$isset_item_title.'">'.__('Download Now!', 'sdm_lang').'</a>';
185
+
186
+ // Generate download buttons
187
+ if ($fancy == '0') {
188
+
189
+ $data .= '<div class="sdm_download_link">'.$download_button_code.'</div><br />';
190
+ }
191
+
192
+ if ($fancy == '1') {
193
+
194
+ $data .= '<div class="sdm_download_item">';
195
+ $data .= '<div class="sdm_download_item_top">';
196
+ $data .= '<div class="sdm_download_thumbnail">'.$isset_download_thumbnail.'</div>';
197
+ $data .= '<div class="sdm_download_title">'.$isset_item_title.'</div>';
198
+ $data .= '</div>'; // End of .sdm_download_item_top
199
+ $data .= '<div style="clear:both;"></div>';
200
+ $data .= '<div class="sdm_download_description">'.$isset_item_description.'</div>';
201
+ $data .= '<div class="sdm_download_link">'.$download_button_code.'</div>';
202
+ $data .= '</div>';
203
+ $data .= '<br />';
204
+ }
205
+ } // End foreach
206
+
207
+ // Return results
208
+ return $data;
209
+
210
+ } // End else iterate cpt's
211
+
212
+
213
+ exit;
214
+ }
215
+
216
+ // Create category tree shortcode
217
+ function sdm_download_categories_shortcode() {
218
+
219
+ function custom_taxonomy_walker($taxonomy, $parent = 0) {
220
+
221
+ // Get terms (check if has parent)
222
+ $terms = get_terms($taxonomy, array('parent' => $parent, 'hide_empty' => false));
223
+
224
+ // If there are terms, start displaying
225
+ if(count($terms) > 0) {
226
+ // Displaying as a list
227
+ $out = '<ul>';
228
+ // Cycle though the terms
229
+ foreach ($terms as $term) {
230
+ // Secret sauce. Function calls itself to display child elements, if any
231
+ $out .= '<li class="sdm_cat" id="'.$term->slug.'"><span id="'.$term->term_id.'" class="sdm_cat_title" style="cursor:pointer;">' . $term->name .'</span>';
232
+ $out .= '<p class="sdm_placeholder" style="margin-bottom:0;"></p>' . custom_taxonomy_walker($taxonomy, $term->term_id);
233
+ $out .= '</li>';
234
+ }
235
+ $out .= '</ul>';
236
+ return $out;
237
+ }
238
+ return;
239
+ }
240
+ return '<div class="sdm_object_tree">'.custom_taxonomy_walker('sdm_categories').'</div>';
241
+ }
tinymce/sdm_editor_plugin.js CHANGED
@@ -79,7 +79,8 @@ jQuery(function(){
79
  },
80
  function(response) {
81
  if(response) { // ** If response was successful
82
- console.log(response.test);
 
83
 
84
  jQuery.each(response.test, function (index, value) {
85
  jQuery('#sdm_select').append('<option value="'+value.post_id+'">'+value.post_title+'</option>'); // Populate dropdown list with CPT item titles
@@ -93,22 +94,22 @@ jQuery(function(){
93
 
94
  // Instantiate a form in the wp thickbox window (hidden at start)
95
  var form = jQuery('<div id="highlight-form"><div id="sdm_tinymce_postids" style="display:none;"></div>\
96
- <div id="sdm_select_title" style="margin-top:20px;">Please select a Download Item:</div>\
97
  <table id="highlight-table" class="form-table" style="text-align: left">\
98
  \
99
  \
100
  <tr>\
101
- <th><label class="title" for="highlight-bg">Download Title</label></th>\
102
  <td><select name="sdm_select" id="sdm_select">\
103
  </select><br />\
104
  </tr>\
105
  <tr>\
106
- <th><label class="sdm_fancy" for "sdm_fancy_option">Include Fancy Box</th>\
107
  <td><input type="checkbox" name="sdm_fancy_cb" id="sdm_fancy_cb" />\
108
  </tr>\
109
  </table>\
110
  <p class="submit">\
111
- <input type="button" id="sdm-tinymce-submit" class="button-primary" value="Insert SDM Shortcode" name="submit" style=""/>\
112
  </p>\
113
  <p></p>\
114
  </div>');
79
  },
80
  function(response) {
81
  if(response) { // ** If response was successful
82
+
83
+ //console.log(response.test);
84
 
85
  jQuery.each(response.test, function (index, value) {
86
  jQuery('#sdm_select').append('<option value="'+value.post_id+'">'+value.post_title+'</option>'); // Populate dropdown list with CPT item titles
94
 
95
  // Instantiate a form in the wp thickbox window (hidden at start)
96
  var form = jQuery('<div id="highlight-form"><div id="sdm_tinymce_postids" style="display:none;"></div>\
97
+ <div id="sdm_select_title" style="margin-top:20px;">'+tinymce_langs.select_download_item+'</div>\
98
  <table id="highlight-table" class="form-table" style="text-align: left">\
99
  \
100
  \
101
  <tr>\
102
+ <th><label class="title" for="highlight-bg">'+tinymce_langs.download_title+'</label></th>\
103
  <td><select name="sdm_select" id="sdm_select">\
104
  </select><br />\
105
  </tr>\
106
  <tr>\
107
+ <th><label class="sdm_fancy" for "sdm_fancy_option">'+tinymce_langs.include_fancy+'</th>\
108
  <td><input type="checkbox" name="sdm_fancy_cb" id="sdm_fancy_cb" />\
109
  </tr>\
110
  </table>\
111
  <p class="submit">\
112
+ <input type="button" id="sdm-tinymce-submit" class="button-primary" value="'+tinymce_langs.insert_shortcode+'" name="submit" style=""/>\
113
  </p>\
114
  <p></p>\
115
  </div>');