Version Description
- 2022.01.11 =
- Fixed data sanitization issue on stats page
- Optimized json api calls
Download this release
Release Info
Developer | codename065 |
Plugin | WordPress Download Manager |
Version | 3.2.34 |
Comparing to | |
See all releases |
Code changes from version 3.2.33 to 3.2.34
- download-manager.php +2 -2
- readme.txt +6 -2
- src/Admin/Menu/Packages.php +1 -1
- src/Admin/views/metaboxes/attach-file/upload-file.php +2 -2
- src/Admin/views/stats/history.php +2 -2
- src/Package/PackageController.php +2386 -2015
- src/__/FileSystem.php +6 -5
- src/wpdm-functions.php +2 -5
- src/wpdm-start-download.php +1 -0
download-manager.php
CHANGED
@@ -5,7 +5,7 @@ Plugin URI: https://www.wpdownloadmanager.com/purchases/
|
|
5 |
Description: Manage, Protect and Track file downloads, and sell digital products from your WordPress site. A complete digital asset management solution.
|
6 |
Author: W3 Eden, Inc.
|
7 |
Author URI: https://www.wpdownloadmanager.com/
|
8 |
-
Version: 3.2.
|
9 |
Text Domain: download-manager
|
10 |
Domain Path: /languages
|
11 |
*/
|
@@ -39,7 +39,7 @@ use WPDM\Widgets\WidgetController;
|
|
39 |
|
40 |
global $WPDM;
|
41 |
|
42 |
-
define('WPDM_VERSION','3.2.
|
43 |
|
44 |
define('WPDM_TEXT_DOMAIN','download-manager');
|
45 |
|
5 |
Description: Manage, Protect and Track file downloads, and sell digital products from your WordPress site. A complete digital asset management solution.
|
6 |
Author: W3 Eden, Inc.
|
7 |
Author URI: https://www.wpdownloadmanager.com/
|
8 |
+
Version: 3.2.34
|
9 |
Text Domain: download-manager
|
10 |
Domain Path: /languages
|
11 |
*/
|
39 |
|
40 |
global $WPDM;
|
41 |
|
42 |
+
define('WPDM_VERSION','3.2.34');
|
43 |
|
44 |
define('WPDM_TEXT_DOMAIN','download-manager');
|
45 |
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: download manager, document management, file manager, digital store, ecomme
|
|
5 |
Requires at least: 5.3
|
6 |
Tested up to: 5.8
|
7 |
License: GPLv2 or later
|
8 |
-
Stable tag: 3.2.
|
9 |
|
10 |
|
11 |
This File Management & Digital Store plugin will help you to control file downloads & sell digital products from your WP site.
|
@@ -181,7 +181,11 @@ Check download stats and get a push notification when someone downloads, install
|
|
181 |
|
182 |
== Changelog ==
|
183 |
|
184 |
-
= 3.2.
|
|
|
|
|
|
|
|
|
185 |
* Codebase optimization
|
186 |
* Changed name from `WordPress Download Manager` to `Download Manager`
|
187 |
|
5 |
Requires at least: 5.3
|
6 |
Tested up to: 5.8
|
7 |
License: GPLv2 or later
|
8 |
+
Stable tag: 3.2.34
|
9 |
|
10 |
|
11 |
This File Management & Digital Store plugin will help you to control file downloads & sell digital products from your WP site.
|
181 |
|
182 |
== Changelog ==
|
183 |
|
184 |
+
= 3.2.34 - 2022.01.11 =
|
185 |
+
* Fixed data sanitization issue on stats page
|
186 |
+
* Optimized json api calls
|
187 |
+
|
188 |
+
= 3.2.33 - 2022.01.11 =
|
189 |
* Codebase optimization
|
190 |
* Changed name from `WordPress Download Manager` to `Download Manager`
|
191 |
|
src/Admin/Menu/Packages.php
CHANGED
@@ -60,7 +60,7 @@ class Packages
|
|
60 |
delete_post_meta($post, $k);
|
61 |
|
62 |
}
|
63 |
-
|
64 |
foreach ($_POST['file'] as $meta_key => $meta_value) {
|
65 |
$key_name = "__wpdm_" . $meta_key;
|
66 |
if($meta_key == 'package_dir' && $meta_value != '') {
|
60 |
delete_post_meta($post, $k);
|
61 |
|
62 |
}
|
63 |
+
|
64 |
foreach ($_POST['file'] as $meta_key => $meta_value) {
|
65 |
$key_name = "__wpdm_" . $meta_key;
|
66 |
if($meta_key == 'package_dir' && $meta_value != '') {
|
src/Admin/views/metaboxes/attach-file/upload-file.php
CHANGED
@@ -13,7 +13,7 @@ $afile = wpdm_valueof($afiles, 0);
|
|
13 |
<?php
|
14 |
$filesize = "<em style='color: darkred'>( ".__("attached file is missing/deleted",'download-manager')." )</em>";
|
15 |
$afile = trim($afile);
|
16 |
-
|
17 |
$url = false;
|
18 |
if($afile !=''){
|
19 |
if(substr_count($afile, "://") > 0){
|
@@ -37,7 +37,7 @@ $afile = wpdm_valueof($afiles, 0);
|
|
37 |
<a href="#" id="dcf" title="Delete Current File" class="pull-right" style="font-size:24px">
|
38 |
<i class="fa fa-trash color-red"></i>
|
39 |
</a>
|
40 |
-
<div class="media-body"><strong><?php echo basename($afile); ?></strong><br><span class="text-success"><?php echo
|
41 |
</div>
|
42 |
|
43 |
<?php } else echo "<span style='font-weight:bold;color:#ddd'>". __('No file uploaded yet!', 'download-manager')."</span>"; ?>
|
13 |
<?php
|
14 |
$filesize = "<em style='color: darkred'>( ".__("attached file is missing/deleted",'download-manager')." )</em>";
|
15 |
$afile = trim($afile);
|
16 |
+
|
17 |
$url = false;
|
18 |
if($afile !=''){
|
19 |
if(substr_count($afile, "://") > 0){
|
37 |
<a href="#" id="dcf" title="Delete Current File" class="pull-right" style="font-size:24px">
|
38 |
<i class="fa fa-trash color-red"></i>
|
39 |
</a>
|
40 |
+
<div class="media-body"><strong><?php echo basename($afile); ?></strong><br><span class="text-success"><?php echo $filesize; ?></span></div>
|
41 |
</div>
|
42 |
|
43 |
<?php } else echo "<span style='font-weight:bold;color:#ddd'>". __('No file uploaded yet!', 'download-manager')."</span>"; ?>
|
src/Admin/views/stats/history.php
CHANGED
@@ -22,8 +22,8 @@ $page_no = wpdm_query_var('page_no', 'int') ?: 1;
|
|
22 |
*/
|
23 |
$from_date_string = sanitize_text_field($from_date_string);
|
24 |
$to_date_string = sanitize_text_field($to_date_string);
|
25 |
-
$user_ids =
|
26 |
-
$package_ids =
|
27 |
|
28 |
/**
|
29 |
* Selected/Initial Values for the fields
|
22 |
*/
|
23 |
$from_date_string = sanitize_text_field($from_date_string);
|
24 |
$to_date_string = sanitize_text_field($to_date_string);
|
25 |
+
$user_ids = \WPDM\__\__::sanitize_array($user_ids, 'int');
|
26 |
+
$package_ids = \WPDM\__\__::sanitize_array($package_ids, 'int');
|
27 |
|
28 |
/**
|
29 |
* Selected/Initial Values for the fields
|
src/Package/PackageController.php
CHANGED
@@ -12,272 +12,314 @@ use WPDM\__\Query;
|
|
12 |
use WPDM\__\Session;
|
13 |
use WPDM\__\TempStorage;
|
14 |
|
15 |
-
class PackageController extends PackageTemplate
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
$data['terms_title'] = wpdm_escs(get_post_meta($post_vars['ID'], '__wpdm_terms_title', true));
|
282 |
$data['terms_title'] = !isset($data['terms_title']) || $data['terms_title'] == '' ? __("Terms and Conditions", 'download-manager') : sanitize_text_field($data['terms_title']);
|
283 |
$data['terms_check_label'] = !isset($data['terms_check_label']) || $data['terms_check_label'] == '' ? __("I Agree With Terms and Conditions", 'download-manager') : sanitize_text_field($data['terms_check_label']);
|
@@ -287,685 +329,820 @@ class PackageController extends PackageTemplate
|
|
287 |
//$data['terms_conditions'] = wpautop(strip_tags($data['terms_conditions'], "<p><br><a><strong><b><i>"));
|
288 |
$data['terms_conditions'] = wpautop(wpdm_escs($data['terms_conditions']));*/
|
289 |
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
867 |
|
868 |
-
|
869 |
-
$package['download_url'] = "#";
|
870 |
-
$package['download_link'] = $vars['download_link_extended'] = $vars['download_link_popup'] = stripslashes(get_option('__wpdm_permission_denied_msg'));
|
871 |
-
$package = apply_filters('download_link', $package);
|
872 |
-
if (get_option('_wpdm_hide_all', 0) == 1) {
|
873 |
-
$package['download_link'] = $package['download_link_extended'] = 'blocked';
|
874 |
-
}
|
875 |
-
return $package['download_link'];
|
876 |
-
}
|
877 |
-
if (!@in_array('guest', @maybe_unserialize($package['access'])) && !is_user_logged_in()) {
|
878 |
-
|
879 |
-
$loginform = wpdm_login_form(array('redirect' => get_permalink($package['ID'])));
|
880 |
-
if (get_option('_wpdm_hide_all', 0) == 1) return 'loginform';
|
881 |
-
$package['download_url'] = $vars['download_link_extended'] = $vars['download_link_popup'] = home_url('/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
|
882 |
-
$loginmsg = Messages::login_required($package['ID']);
|
883 |
-
$package['download_link'] = stripcslashes(str_replace(array("[loginform]", "[this_url]", "[package_url]"), array($loginform, $_SERVER['REQUEST_URI'], get_permalink($package['ID'])), $loginmsg));
|
884 |
-
return get_option('__wpdm_login_form', 0) == 1 ? $loginform : $package['download_link'];
|
885 |
-
|
886 |
-
}
|
887 |
-
|
888 |
-
$package = apply_filters('download_link', $package);
|
889 |
|
890 |
-
|
891 |
|
892 |
-
|
893 |
-
|
894 |
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
|
900 |
|
901 |
-
|
902 |
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
|
912 |
-
|
913 |
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
|
918 |
-
|
919 |
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
|
924 |
-
|
925 |
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
|
930 |
-
|
931 |
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
|
936 |
-
|
937 |
|
938 |
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
|
943 |
-
|
944 |
|
945 |
-
|
946 |
-
|
947 |
|
948 |
-
|
949 |
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
|
|
954 |
|
955 |
-
|
956 |
-
|
957 |
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
|
|
|
|
|
|
969 |
|
970 |
// if ($popstyle == 'pop-over') {
|
971 |
// if(!get_option('__wpdm_ajax_popup', false))
|
@@ -974,418 +1151,480 @@ class PackageController extends PackageTemplate
|
|
974 |
// else
|
975 |
// $adata .= '<div class="modal fade" role="modal" id="pkg_' . $package['ID'] . "_" . $unqid . '"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><strong style="margin:0px;font-size:12pt">' . __('Download') . '</strong></div><div class="modal-body">' . $data . '</div><div class="modal-footer text-right"><button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Close</button></div></div></div></div>';
|
976 |
|
977 |
-
|
978 |
-
|
979 |
-
$data = $adata;
|
980 |
-
}
|
981 |
-
if ($lock !== 'locked') {
|
982 |
-
|
983 |
-
$data = $package['download_link'];
|
984 |
-
|
985 |
-
|
986 |
-
}
|
987 |
-
} else {
|
988 |
-
$data = Messages::download_limit_exceeded($package['ID']);
|
989 |
-
}
|
990 |
-
|
991 |
-
|
992 |
-
//return str_replace(array("\r","\n"),"",$data);
|
993 |
-
return $data;
|
994 |
-
|
995 |
-
}
|
996 |
-
|
997 |
-
private static function activeLocks($ID, $params = array('embed' => 0, 'popstyle' => 'pop-over'))
|
998 |
-
{
|
999 |
-
|
1000 |
-
$embed = isset($params['embed']) ? $params['embed'] : 0;
|
1001 |
-
$template_type = isset($params['template_type']) ? $params['template_type'] : 'link';
|
1002 |
-
$popstyle = isset($params['popstyle']) ? $params['popstyle'] : 'pop-over';
|
1003 |
-
|
1004 |
-
$package = array(
|
1005 |
-
'ID' => $ID,
|
1006 |
-
'password' => get_post_meta($ID, '__wpdm_password', true),
|
1007 |
-
'password_lock' => get_post_meta($ID, '__wpdm_password_lock', true),
|
1008 |
-
'email_lock' => get_post_meta($ID, '__wpdm_email_lock', true),
|
1009 |
-
'linkedin_lock' => get_post_meta($ID, '__wpdm_linkedin_lock', true),
|
1010 |
-
'twitterfollow_lock' => get_post_meta($ID, '__wpdm_twitterfollow_lock', true),
|
1011 |
-
'gplusone_lock' => get_post_meta($ID, '__wpdm_gplusone_lock', true),
|
1012 |
-
'tweet_lock' => get_post_meta($ID, '__wpdm_tweet_lock', true),
|
1013 |
-
'facebooklike_lock' => get_post_meta($ID, '__wpdm_facebooklike_lock', true),
|
1014 |
-
'captcha_lock' => get_post_meta($ID, '__wpdm_captcha_lock', true),
|
1015 |
-
);
|
1016 |
-
|
1017 |
-
$package = apply_filters('wpdm_before_apply_locks', $package);
|
1018 |
-
$lock = $data = "";
|
1019 |
-
$unqid = uniqid();
|
1020 |
-
|
1021 |
-
if (isset($package['password_lock']) && (int)$package['password_lock'] == 1 && $package['password'] != '') {
|
1022 |
-
$lock = 'locked';
|
1023 |
-
$data = PackageLocks::AskPassword($package);
|
1024 |
-
}
|
1025 |
-
|
1026 |
-
$sociallock = "";
|
1027 |
-
|
1028 |
-
if (isset($package['email_lock']) && (int)$package['email_lock'] == 1) {
|
1029 |
-
$data .= PackageLocks::AskEmail($package);
|
1030 |
-
$lock = 'locked';
|
1031 |
-
}
|
1032 |
-
|
1033 |
-
if (isset($package['linkedin_lock']) && (int)$package['linkedin_lock'] == 1) {
|
1034 |
-
$lock = 'locked';
|
1035 |
-
$sociallock .= PackageLocks::LinkedInShare($package);
|
1036 |
-
|
1037 |
-
}
|
1038 |
-
|
1039 |
-
if (isset($package['twitterfollow_lock']) && (int)$package['twitterfollow_lock'] == 1) {
|
1040 |
-
$lock = 'locked';
|
1041 |
-
$sociallock .= PackageLocks::TwitterFollow($package);
|
1042 |
-
|
1043 |
-
}
|
1044 |
-
|
1045 |
-
if (isset($package['gplusone_lock']) && (int)$package['gplusone_lock'] == 1) {
|
1046 |
-
$lock = 'locked';
|
1047 |
-
$sociallock .= PackageLocks::GooglePlusOne($package, true);
|
1048 |
-
|
1049 |
-
}
|
1050 |
-
|
1051 |
-
if (isset($package['tweet_lock']) && (int)$package['tweet_lock'] == 1) {
|
1052 |
-
$lock = 'locked';
|
1053 |
-
$sociallock .= PackageLocks::Tweet($package);
|
1054 |
-
|
1055 |
-
}
|
1056 |
-
|
1057 |
-
if (isset($package['facebooklike_lock']) && (int)$package['facebooklike_lock'] == 1) {
|
1058 |
-
$lock = 'locked';
|
1059 |
-
$sociallock .= PackageLocks::FacebookLike($package, true);
|
1060 |
-
|
1061 |
-
}
|
1062 |
-
|
1063 |
-
|
1064 |
-
$extralocks = '';
|
1065 |
-
$extralocks = apply_filters("wpdm_download_lock", $extralocks, $package);
|
1066 |
-
|
1067 |
-
if (is_array($extralocks) && $extralocks['lock'] === 'locked') {
|
1068 |
-
|
1069 |
-
if (isset($extralocks['type']) && $extralocks['type'] == 'social')
|
1070 |
-
$sociallock .= $extralocks['html'];
|
1071 |
-
else
|
1072 |
-
$data .= $extralocks['html'];
|
1073 |
-
|
1074 |
-
$lock = 'locked';
|
1075 |
-
}
|
1076 |
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
$data .= "<div class='panel panel-default card'><div class='panel-heading card-header'>" . get_option('_wpdm_social_lock_panel_title', 'Like or Share to Download') . "</div><div class='panel-body card-body wpdm-social-locks text-center'>{$socdesc}{$sociallock}</div></div>";
|
1081 |
-
}
|
1082 |
|
|
|
1083 |
|
1084 |
-
if (isset($package['captcha_lock']) && (int)$package['captcha_lock'] == 1) {
|
1085 |
-
$lock = 'locked';
|
1086 |
-
$captcha = PackageLocks::reCaptchaLock($package, true);
|
1087 |
-
$data .= $captcha; //"<div class='panel panel-default card'><div class='panel-heading card-header'>" . __("Verify CAPTCHA to Download", "download-manager") . "</div><div class='panel-body card-body wpdm-social-locks text-center'>{$captcha}</div></div>";
|
1088 |
-
}
|
1089 |
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
else {
|
1095 |
-
$link_label = get_post_meta($ID, '__wpdm_link_label', true);
|
1096 |
-
$link_label = trim($link_label) ? $link_label : __("Download", "download-manager");
|
1097 |
-
$style = wpdm_download_button_style(($template_type === 'page'), $ID);
|
1098 |
-
$style = isset($params['btnclass']) && $params['btnclass'] !== '' ? $params['btnclass'] : $style;
|
1099 |
-
$adata = '<a href="#pkg_' . $ID . "_" . $unqid . '" data-package="' . $ID . '" data-trigger="manual" class="wpdm-download-link wpdm-download-locked ' . $style . '">' . $link_label . '</a>';
|
1100 |
|
1101 |
-
}
|
1102 |
|
1103 |
-
|
1104 |
-
|
1105 |
-
return $data;
|
1106 |
-
}
|
1107 |
-
|
1108 |
-
|
1109 |
-
/**
|
1110 |
-
* @usage Generate download link of a package
|
1111 |
-
* @param $package
|
1112 |
-
* @param int $embed
|
1113 |
-
* @param array $extras
|
1114 |
-
* @return string
|
1115 |
-
*/
|
1116 |
-
public function downloadLink($ID, $embed = 0, $extras = array())
|
1117 |
-
{
|
1118 |
-
global $wpdb, $current_user, $wpdm_download_icon, $wpdm_download_lock_icon;
|
1119 |
-
if (is_array($extras))
|
1120 |
-
extract($extras);
|
1121 |
-
$data = '';
|
1122 |
|
1123 |
-
|
1124 |
|
1125 |
-
|
1126 |
|
1127 |
-
|
1128 |
-
|
|
|
1129 |
|
1130 |
-
|
1131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1132 |
|
1133 |
-
|
|
|
|
|
1134 |
|
1135 |
-
|
|
|
|
|
|
|
1136 |
|
1137 |
-
|
1138 |
-
$alert_size = ($template_type == 'link') ? 'alert-sm' : '';
|
1139 |
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
$limit_over = 1;
|
1145 |
-
}
|
1146 |
|
1147 |
-
|
1148 |
-
|
|
|
1149 |
|
1150 |
-
|
1151 |
-
$download_url = '#';
|
1152 |
-
$link_label = __("Download was expired on", "download-manager") . " " . date_i18n(get_option('date_format') . " h:i A", strtotime($expired));
|
1153 |
-
return "<div class='alert alert-warning {$alert_size}' data-title='" . __("DOWNLOAD ERROR:", "download-manager") . "'>{$link_label}</div>";
|
1154 |
-
}
|
1155 |
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
return "<div class='alert alert-warning {$alert_size}' data-title='" . __("DOWNLOAD ERROR:", "download-manager") . "'>{$link_label}</div>";
|
1160 |
-
}
|
1161 |
|
|
|
1162 |
|
1163 |
-
|
1164 |
-
|
|
|
1165 |
|
1166 |
-
|
1167 |
-
$download_link = $download_link_extended = $download_link_popup = (int)get_option('__wpdm_mask_dlink', 1) === 1 ? "<a class='wpdm-download-link download-on-click {$style}' rel='nofollow' href='#' data-downloadurl=\"{$download_url}\">{$link_label}</a>" : "<a class='wpdm-download-link {$style}' rel='nofollow' href='{$download_url}'>{$link_label}</a>";
|
1168 |
-
//$download_link = $download_link_extended = $download_link_popup = (int)get_option('__wpdm_mask_dlink', 1) === 1 ? "<a class='wpdm-download-link {$style}' rel='nofollow' href='#' onclick=\"location.href='{$download_url}';return false;\">{$link_label}</a>" : "<a class='wpdm-download-link {$style}' rel='nofollow' href='{$download_url}'>{$link_label}</a>";
|
1169 |
-
else
|
1170 |
-
$download_link = "<div class='alert alert-warning {$alert_size}' data-title='" . __("DOWNLOAD ERROR:", "download-manager") . "'>{$link_label}</div>";
|
1171 |
|
|
|
|
|
|
|
1172 |
|
1173 |
-
|
1174 |
-
if (!is_array($access)) $access = array();
|
1175 |
-
$matched = (is_array($access) && is_user_logged_in()) ? array_intersect($current_user->roles, $access) : array();
|
1176 |
-
if (!$matched) $matched = [];
|
1177 |
|
1178 |
-
|
|
|
|
|
1179 |
|
1180 |
-
|
1181 |
-
if (is_user_logged_in() && count($matched) <= 0 && !@in_array('guest', $access)) {
|
1182 |
-
$download_url = "#";
|
1183 |
-
$download_link = $download_link_extended = $download_link_popup = Messages::permission_denied($ID);
|
1184 |
-
if (get_option('_wpdm_hide_all', 0) == 1) {
|
1185 |
-
$download_link = $download_link_extended = $download_link_popup = 'blocked';
|
1186 |
-
}
|
1187 |
-
return $download_link;
|
1188 |
-
}
|
1189 |
|
1190 |
-
//Login is required to download
|
1191 |
-
if (!@in_array('guest', $access) && !is_user_logged_in()) {
|
1192 |
|
1193 |
-
|
1194 |
-
|
1195 |
-
$hide_all_message = get_option('__wpdm_login_form', 0) == 1 ? $loginform : stripcslashes(str_replace(array("[loginform]", "[this_url]", "[package_url]"), array($loginform, $_SERVER['REQUEST_URI'], get_permalink($ID)), $loginmsg));
|
1196 |
-
if ($template_type == 'link')
|
1197 |
-
return "<a href='" . wpdm_login_url($_SERVER['REQUEST_URI']) . "' class='btn btn-danger'>" . __("Login", "download-manager") . "</a>";
|
1198 |
-
else
|
1199 |
-
return $hide_all_message;
|
1200 |
-
}
|
1201 |
-
$download_url = wpdm_login_url($_SERVER['REQUEST_URI']);
|
1202 |
-
$download_link = $download_link_extended = $download_link_popup = stripcslashes(str_replace(array("[loginform]", "[this_url]", "[package_url]"), array($loginform, $_SERVER['REQUEST_URI'], get_permalink($ID)), $loginmsg));
|
1203 |
-
return get_option('__wpdm_login_form', 0) == 1 ? $loginform : $download_link;
|
1204 |
|
1205 |
-
|
1206 |
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
$download_count = (int)get_post_meta($ID, '__wpdm_download_count', true);
|
1213 |
-
if ($stock_limit > $download_count || $stock_limit == 0) {
|
1214 |
-
$lock = 0;
|
1215 |
-
|
1216 |
-
$extras['embed'] = $embed;
|
1217 |
-
$data = self::activeLocks($ID, $extras);
|
1218 |
-
|
1219 |
-
$terms_lock = (int)get_post_meta($ID, '__wpdm_terms_lock', true);
|
1220 |
-
$terms_page = (int)get_post_meta($ID, '__wpdm_terms_page', true);
|
1221 |
-
$terms_title = get_post_meta($ID, '__wpdm_terms_title', true);
|
1222 |
-
$terms_conditions = get_post_meta($ID, '__wpdm_terms_conditions', true);
|
1223 |
-
if ($terms_page) {
|
1224 |
-
$terms_page = get_post($terms_page);
|
1225 |
-
$terms_title = $terms_page->post_title;
|
1226 |
-
$terms_conditions = $terms_page->post_content;
|
1227 |
-
}
|
1228 |
-
$terms_check_label = get_post_meta($ID, '__wpdm_terms_check_label', true);
|
1229 |
-
if ($terms_lock !== 0 && (!function_exists('wpdmpp_effective_price') || wpdmpp_effective_price($ID) == 0)) {
|
1230 |
-
if (!self::isLocked($ID) && !$embed) {
|
1231 |
-
$data = "<a href='#unlock' class='wpdm-download-link wpdm-download-locked {$style}' data-package='{$ID}'>{$link_label}</a>";
|
1232 |
-
} else {
|
1233 |
-
$data = $data ? $data : $download_link;
|
1234 |
-
}
|
1235 |
-
if ($embed == 1)
|
1236 |
-
$data = "<div class='panel panel-default card terms-panel' style='margin: 0 0 10px 0'><div class='panel-heading card-header'>{$terms_title}</div><div class='panel-body card-body' style='max-height: 200px;overflow: auto'>{$terms_conditions}</div><div class='panel-footer card-footer'><label><input data-pid='{$ID}' class='wpdm-checkbox terms_checkbox terms_checkbox_{$ID}' type='checkbox'> {$terms_check_label}</label></div><div class='panel-footer card-footer bg-white download_footer_{$ID}' style='display:none;'>{$data}</div></div><script>jQuery(function($){ $('#wpdm-filelist-{$ID} .btn.inddl, #xfilelist .btn.inddl').attr('disabled', 'disabled'); });</script>";
|
1237 |
|
1238 |
-
|
|
|
1239 |
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
|
|
1244 |
|
1245 |
|
1246 |
-
|
|
|
|
|
|
|
|
|
1247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1248 |
|
1249 |
-
|
1250 |
-
$data = "<button class='btn btn-danger btn-block' type='button' disabled='disabled' data-title='DOWNLOAD ERROR:'>" . __("Limit Over!", "download-manager") . "</button>";
|
1251 |
-
}
|
1252 |
-
if ($data == 'loginform') return WPDM()->user->login->form();
|
1253 |
-
$data = apply_filters('wpdm_download_link', $data, $extras + array('ID' => $ID, 'id' => $ID));
|
1254 |
-
return $data;
|
1255 |
-
|
1256 |
-
}
|
1257 |
-
|
1258 |
-
/**
|
1259 |
-
* @usage Generate download url for public/open downloads, the url will not work for the packages with lock option
|
1260 |
-
* @param $ID
|
1261 |
-
* @param $ext
|
1262 |
-
* @return string
|
1263 |
-
*/
|
1264 |
-
public function getDownloadURL($ID, $ext = array())
|
1265 |
-
{
|
1266 |
-
if (self::isLocked($ID) && !Session::get('__wpdm_unlocked_' . $ID)) return '#locked';
|
1267 |
-
if (!is_array($ext)) $ext = [];
|
1268 |
-
$ext['wpdmdl'] = $ID;
|
1269 |
-
$ext['refresh'] = uniqid() . time();
|
1270 |
-
$permalink = get_permalink($ID);
|
1271 |
-
$permalink = apply_filters("wpdm_download_url_base", $permalink, $ID);
|
1272 |
-
$download_url = add_query_arg($ext, $permalink);
|
1273 |
-
$flat = (int)get_option('__wpdm_flat_download_url', 0);
|
1274 |
-
$code = json_encode($ext);
|
1275 |
-
$code = base64_encode($code);
|
1276 |
-
$code = rtrim($code, '=');
|
1277 |
-
$filename = isset($ext['filename']) ? $ext['filename'] : '';
|
1278 |
-
if (isset($ext['ind']) && $filename == '') {
|
1279 |
-
$files = $this->getFiles($ID);
|
1280 |
-
$filename = wpdm_basename($files[$ext['ind']]);
|
1281 |
-
}
|
1282 |
-
if (!isset($ext['ind']) && $filename == '') {
|
1283 |
-
$files = $this->getFiles($ID);
|
1284 |
-
if (count($files) > 1)
|
1285 |
-
$filename = sanitize_file_name(get_the_title($ID)) . ".zip";
|
1286 |
-
else {
|
1287 |
-
$filename = array_shift($files);
|
1288 |
-
$filename = wpdm_basename($filename);
|
1289 |
-
}
|
1290 |
|
1291 |
-
|
1292 |
-
|
1293 |
-
return $download_url;
|
1294 |
-
}
|
1295 |
-
|
1296 |
-
/**
|
1297 |
-
* @param $ID
|
1298 |
-
* @return false|string
|
1299 |
-
*/
|
1300 |
-
public function getMasterDownloadURL($ID)
|
1301 |
-
{
|
1302 |
-
$package_url = get_permalink($ID);
|
1303 |
-
$params['wpdmdl'] = $ID;
|
1304 |
-
$params['masterkey'] = get_post_meta($ID, '__wpdm_masterkey', true);
|
1305 |
-
$download_url = add_query_arg($params, $package_url);
|
1306 |
-
return $download_url;
|
1307 |
-
}
|
1308 |
-
|
1309 |
-
/**
|
1310 |
-
* @param $ID
|
1311 |
-
* @param $Key
|
1312 |
-
* @return bool
|
1313 |
-
*/
|
1314 |
-
public function validateMasterKey($ID, $Key)
|
1315 |
-
{
|
1316 |
-
if ($Key === '') return false;
|
1317 |
-
$masterKey = get_post_meta($ID, '__wpdm_masterkey', true);
|
1318 |
-
if ($masterKey === '') return false;
|
1319 |
-
if ($masterKey === $Key) return true;
|
1320 |
-
return false;
|
1321 |
-
}
|
1322 |
-
|
1323 |
-
/**
|
1324 |
-
* @param $ID
|
1325 |
-
* @param int $usageLimit
|
1326 |
-
* @param int $expirePeriod seconds
|
1327 |
-
* @return string
|
1328 |
-
*/
|
1329 |
-
function expirableDownloadLink($ID, $usageLimit = 10, $expirePeriod = 999999, $sessionOnly = true)
|
1330 |
-
{
|
1331 |
-
$key = uniqid();
|
1332 |
-
$exp = array('use' => $usageLimit, 'expire' => time() + $expirePeriod);
|
1333 |
-
if (!$sessionOnly)
|
1334 |
-
update_post_meta($ID, "__wpdmkey_" . $key, $exp);
|
1335 |
-
else
|
1336 |
-
TempStorage::set("__wpdmkey_{$key}", $exp, time() + $expirePeriod);
|
1337 |
-
//Session::set( '__wpdm_unlocked_'.$ID , 1 );
|
1338 |
-
//$download_url = $this->getDownloadURL($ID, "_wpdmkey={$key}");
|
1339 |
-
$permalink = get_permalink($ID);
|
1340 |
-
$permalink = apply_filters("wpdm_download_url_base", $permalink, $ID);
|
1341 |
-
$download_url = add_query_arg(array("wpdmdl" => $ID, "_wpdmkey" => $key), $permalink);
|
1342 |
-
return $download_url;
|
1343 |
-
}
|
1344 |
-
|
1345 |
-
/**
|
1346 |
-
* @param $ID
|
1347 |
-
* @param int $usageLimit
|
1348 |
-
* @param int $expirePeriod seconds
|
1349 |
-
* @return string
|
1350 |
-
*/
|
1351 |
-
static function expirableDownloadPage($ID, $usageLimit = 10, $expirePeriod = 604800, $sessionOnly = true)
|
1352 |
-
{
|
1353 |
-
$key = uniqid();
|
1354 |
-
$exp = array('use' => $usageLimit, 'expire' => time() + $expirePeriod);
|
1355 |
-
if (!$sessionOnly)
|
1356 |
-
update_post_meta($ID, "__wpdmkey_" . $key, $exp);
|
1357 |
-
else
|
1358 |
-
TempStorage::set("__wpdmkey_{$key}", $exp, time() + $expirePeriod);
|
1359 |
-
$download_page_key = Crypt::encrypt(array('pid' => $ID, 'key' => $key));
|
1360 |
-
$download_page = home_url("wpdm-download/{$download_page_key}");
|
1361 |
-
return $download_page;
|
1362 |
-
}
|
1363 |
-
|
1364 |
-
|
1365 |
-
/**
|
1366 |
-
* @usage Fetch link/page template and return generated html
|
1367 |
-
* @param $template
|
1368 |
-
* @param $vars
|
1369 |
-
* @param string $type
|
1370 |
-
* @return mixed|string
|
1371 |
-
*/
|
1372 |
-
public function fetchTemplate($template, $vars, $type = 'link')
|
1373 |
-
{
|
1374 |
-
if (!is_array($vars) && is_int($vars) && $vars > 0) $vars = array('ID' => $vars);
|
1375 |
-
if (!isset($vars['ID']) || intval($vars['ID']) < 1) return '';
|
1376 |
|
1377 |
-
|
|
|
1378 |
|
1379 |
-
if (!is_user_logged_in() && count(self::allowedRoles($vars['ID'])) >= 0 && !self::userCanAccess($vars['ID'])) {
|
1380 |
-
$loginform = wpdm_login_form(array('redirect' => get_permalink($vars['ID'])));
|
1381 |
-
$hide_all_message = get_option('__wpdm_login_form', 0) == 1 ? $loginform : stripcslashes(str_replace(array("[loginform]", "[this_url]", "[package_url]"), array($loginform, $_SERVER['REQUEST_URI'], get_permalink($vars['ID'])), $loginmsg));
|
1382 |
-
if (get_option('_wpdm_hide_all', 0) == 1) return $type == 'page' ? $hide_all_message : '';
|
1383 |
-
}
|
1384 |
|
1385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1386 |
|
|
|
|
|
|
|
|
|
1387 |
|
1388 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1389 |
$default['page'] = 'page-template-default.php';
|
1390 |
|
1391 |
|
@@ -1438,186 +1677,228 @@ class PackageController extends PackageTemplate
|
|
1438 |
|
1439 |
}*/
|
1440 |
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
|
1516 |
-
|
1517 |
-
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
|
1526 |
-
|
1527 |
-
|
1528 |
-
|
1529 |
-
|
1530 |
-
|
1531 |
-
|
1532 |
-
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
1536 |
-
|
1537 |
-
|
1538 |
-
|
1539 |
-
|
1540 |
-
|
1541 |
-
|
1542 |
-
|
1543 |
-
|
1544 |
-
|
1545 |
-
|
1546 |
-
|
1547 |
-
|
1548 |
-
|
1549 |
-
|
1550 |
-
|
1551 |
-
|
1552 |
-
|
1553 |
-
|
1554 |
-
|
1555 |
-
|
1556 |
-
|
1557 |
-
|
1558 |
-
|
1559 |
-
|
1560 |
-
|
1561 |
-
|
1562 |
-
|
1563 |
-
|
1564 |
-
|
1565 |
-
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
$vars['
|
1570 |
-
|
1571 |
-
|
1572 |
-
|
1573 |
-
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
|
1578 |
-
|
1579 |
-
|
1580 |
-
|
1581 |
-
|
1582 |
-
|
1583 |
-
|
1584 |
-
|
1585 |
-
|
1586 |
-
|
1587 |
-
|
1588 |
-
|
1589 |
-
|
1590 |
-
|
1591 |
-
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
|
1615 |
-
|
1616 |
-
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1621 |
{
|
1622 |
|
1623 |
if (!strpos(strip_tags($template), "]")) {
|
@@ -1662,550 +1943,640 @@ class PackageController extends PackageTemplate
|
|
1662 |
return $template;
|
1663 |
}*/
|
1664 |
|
1665 |
-
|
1666 |
-
|
1667 |
-
|
1668 |
-
|
1669 |
-
|
1670 |
-
|
1671 |
-
|
1672 |
-
|
1673 |
-
|
1674 |
-
|
1675 |
-
|
1676 |
-
|
1677 |
-
|
1678 |
-
|
1679 |
-
|
1680 |
-
|
1681 |
-
|
1682 |
-
|
1683 |
-
|
1684 |
-
|
1685 |
-
|
1686 |
-
|
1687 |
-
|
1688 |
-
|
1689 |
-
|
1690 |
-
|
1691 |
-
|
1692 |
-
|
1693 |
-
|
1694 |
-
|
1695 |
-
|
1696 |
-
|
1697 |
-
|
1698 |
-
|
1699 |
-
|
1700 |
-
|
1701 |
-
|
1702 |
-
|
1703 |
-
|
1704 |
-
|
1705 |
-
|
1706 |
-
|
1707 |
-
|
1708 |
-
|
1709 |
-
|
1710 |
-
|
1711 |
-
|
1712 |
-
|
1713 |
-
|
1714 |
-
|
1715 |
-
|
1716 |
-
|
1717 |
-
|
1718 |
-
|
1719 |
-
|
1720 |
-
|
1721 |
-
|
1722 |
-
|
1723 |
-
|
1724 |
-
|
1725 |
-
|
1726 |
-
|
1727 |
-
|
1728 |
-
|
1729 |
-
|
1730 |
-
|
1731 |
-
|
1732 |
-
|
1733 |
-
|
1734 |
-
|
1735 |
-
|
1736 |
-
|
1737 |
-
|
1738 |
-
|
1739 |
-
|
1740 |
-
|
1741 |
-
|
1742 |
-
|
1743 |
-
|
1744 |
-
|
1745 |
-
|
1746 |
-
|
1747 |
-
|
1748 |
-
|
1749 |
-
|
1750 |
-
|
1751 |
-
|
1752 |
-
|
1753 |
-
|
1754 |
-
|
1755 |
-
|
1756 |
-
|
1757 |
-
|
1758 |
-
|
1759 |
-
|
1760 |
-
|
1761 |
-
|
1762 |
-
|
1763 |
-
|
1764 |
-
|
1765 |
-
|
1766 |
-
|
1767 |
-
|
1768 |
-
|
1769 |
-
|
1770 |
-
|
1771 |
-
|
1772 |
-
|
1773 |
-
|
1774 |
-
|
1775 |
-
|
1776 |
-
|
1777 |
-
|
1778 |
-
|
1779 |
-
|
1780 |
-
|
1781 |
-
|
1782 |
-
|
1783 |
-
|
1784 |
-
|
1785 |
-
|
1786 |
-
|
1787 |
-
|
1788 |
-
|
1789 |
-
|
1790 |
-
|
1791 |
-
|
1792 |
-
|
1793 |
-
|
1794 |
-
|
1795 |
-
|
1796 |
-
|
1797 |
-
|
1798 |
-
|
1799 |
-
|
1800 |
-
|
1801 |
-
|
1802 |
-
|
1803 |
-
|
1804 |
-
|
1805 |
-
|
1806 |
-
|
1807 |
-
|
1808 |
-
|
1809 |
-
|
1810 |
-
|
1811 |
-
|
1812 |
-
|
1813 |
-
|
1814 |
-
|
1815 |
-
|
1816 |
-
|
1817 |
-
|
1818 |
-
|
1819 |
-
|
1820 |
-
|
1821 |
-
|
1822 |
-
|
1823 |
-
|
1824 |
-
|
1825 |
-
|
1826 |
-
|
1827 |
-
|
1828 |
-
|
1829 |
-
|
1830 |
-
|
1831 |
-
|
1832 |
-
|
1833 |
-
|
1834 |
-
|
1835 |
-
|
1836 |
-
|
1837 |
-
|
1838 |
-
|
1839 |
-
|
1840 |
-
|
1841 |
-
|
1842 |
-
|
1843 |
-
|
1844 |
-
|
1845 |
-
|
1846 |
-
|
1847 |
-
|
1848 |
-
|
1849 |
-
|
1850 |
-
|
1851 |
-
|
1852 |
-
|
1853 |
-
|
1854 |
-
|
1855 |
-
|
1856 |
-
|
1857 |
-
|
1858 |
-
|
1859 |
-
|
1860 |
-
|
1861 |
-
|
1862 |
-
|
1863 |
-
|
1864 |
-
|
1865 |
-
|
1866 |
-
|
1867 |
-
|
1868 |
-
|
1869 |
-
|
1870 |
-
|
1871 |
-
|
1872 |
-
|
1873 |
-
|
1874 |
-
|
1875 |
-
|
1876 |
-
|
1877 |
-
|
1878 |
-
|
1879 |
-
|
1880 |
-
|
1881 |
-
|
1882 |
-
|
1883 |
-
|
1884 |
-
|
1885 |
-
|
1886 |
-
|
1887 |
-
|
1888 |
-
|
1889 |
-
|
1890 |
-
|
1891 |
-
|
1892 |
-
|
1893 |
-
|
1894 |
-
|
1895 |
-
|
1896 |
-
|
1897 |
-
|
1898 |
-
|
1899 |
-
|
1900 |
-
|
1901 |
-
|
1902 |
-
|
1903 |
-
|
1904 |
-
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
|
1910 |
-
|
1911 |
-
|
1912 |
-
|
1913 |
-
|
1914 |
-
|
1915 |
-
|
1916 |
-
|
1917 |
-
|
1918 |
-
|
1919 |
-
|
1920 |
-
|
1921 |
-
|
1922 |
-
|
1923 |
-
|
1924 |
-
|
1925 |
-
|
1926 |
-
|
1927 |
-
|
1928 |
-
|
1929 |
-
|
1930 |
-
|
1931 |
-
|
1932 |
-
|
1933 |
-
|
1934 |
-
|
1935 |
-
|
1936 |
-
|
1937 |
-
|
1938 |
-
|
1939 |
-
|
1940 |
-
|
1941 |
-
|
1942 |
-
|
1943 |
-
|
1944 |
-
|
1945 |
-
|
1946 |
-
|
1947 |
-
|
1948 |
-
|
1949 |
-
|
1950 |
-
|
1951 |
-
|
1952 |
-
|
1953 |
-
|
1954 |
-
|
1955 |
-
|
1956 |
-
|
1957 |
-
|
1958 |
-
|
1959 |
-
|
1960 |
-
|
1961 |
-
|
1962 |
-
|
1963 |
-
|
1964 |
-
|
1965 |
-
|
1966 |
-
|
1967 |
-
|
1968 |
-
|
1969 |
-
|
1970 |
-
|
1971 |
-
|
1972 |
-
|
1973 |
-
|
1974 |
-
|
1975 |
-
|
1976 |
-
|
1977 |
-
|
1978 |
-
|
1979 |
-
|
1980 |
-
|
1981 |
-
|
1982 |
-
|
1983 |
-
|
1984 |
-
|
1985 |
-
|
1986 |
-
|
1987 |
-
|
1988 |
-
|
1989 |
-
|
1990 |
-
|
1991 |
-
|
1992 |
-
|
1993 |
-
|
1994 |
-
|
1995 |
-
|
1996 |
-
|
1997 |
-
|
1998 |
-
|
1999 |
-
|
2000 |
-
|
2001 |
-
|
2002 |
-
|
2003 |
-
|
2004 |
-
|
2005 |
-
|
2006 |
-
|
2007 |
-
|
2008 |
-
|
2009 |
-
|
2010 |
-
|
2011 |
-
|
2012 |
-
|
2013 |
-
|
2014 |
-
|
2015 |
-
|
2016 |
-
|
2017 |
-
|
2018 |
-
|
2019 |
-
|
2020 |
-
|
2021 |
-
|
2022 |
-
|
2023 |
-
|
2024 |
-
|
2025 |
-
|
2026 |
-
|
2027 |
-
|
2028 |
-
|
2029 |
-
|
2030 |
-
|
2031 |
-
|
2032 |
-
|
2033 |
-
|
2034 |
-
|
2035 |
-
|
2036 |
-
|
2037 |
-
|
2038 |
-
|
2039 |
-
|
2040 |
-
|
2041 |
-
|
2042 |
-
|
2043 |
-
|
2044 |
-
|
2045 |
-
|
2046 |
-
|
2047 |
-
|
2048 |
-
|
2049 |
-
|
2050 |
-
|
2051 |
-
|
2052 |
-
|
2053 |
-
|
2054 |
-
|
2055 |
-
|
2056 |
-
|
2057 |
-
|
2058 |
-
|
2059 |
-
|
2060 |
-
|
2061 |
-
|
2062 |
-
|
2063 |
-
|
2064 |
-
|
2065 |
-
|
2066 |
-
|
2067 |
-
|
2068 |
-
|
2069 |
-
|
2070 |
-
|
2071 |
-
|
2072 |
-
|
2073 |
-
|
2074 |
-
|
2075 |
-
|
2076 |
-
|
2077 |
-
|
2078 |
-
|
2079 |
-
|
2080 |
-
|
2081 |
-
|
2082 |
-
|
2083 |
-
|
2084 |
-
|
2085 |
-
|
2086 |
-
|
2087 |
-
|
2088 |
-
|
2089 |
-
|
2090 |
-
|
2091 |
-
|
2092 |
-
|
2093 |
-
|
2094 |
-
|
2095 |
-
|
2096 |
-
|
2097 |
-
|
2098 |
-
|
2099 |
-
|
2100 |
-
|
2101 |
-
|
2102 |
-
|
2103 |
-
|
2104 |
-
|
2105 |
-
|
2106 |
-
|
2107 |
-
|
2108 |
-
|
2109 |
-
|
2110 |
-
|
2111 |
-
|
2112 |
-
|
2113 |
-
|
2114 |
-
|
2115 |
-
|
2116 |
-
|
2117 |
-
|
2118 |
-
|
2119 |
-
|
2120 |
-
|
2121 |
-
|
2122 |
-
|
2123 |
-
|
2124 |
-
|
2125 |
-
|
2126 |
-
|
2127 |
-
|
2128 |
-
|
2129 |
-
|
2130 |
-
|
2131 |
-
|
2132 |
-
|
2133 |
-
|
2134 |
-
|
2135 |
-
|
2136 |
-
|
2137 |
-
|
2138 |
-
|
2139 |
-
|
2140 |
-
|
2141 |
-
|
2142 |
-
|
2143 |
-
|
2144 |
-
|
2145 |
-
|
2146 |
-
|
2147 |
-
|
2148 |
-
|
2149 |
-
|
2150 |
-
|
2151 |
-
|
2152 |
-
|
2153 |
-
|
2154 |
-
|
2155 |
-
|
2156 |
-
|
2157 |
-
|
2158 |
-
|
2159 |
-
|
2160 |
-
|
2161 |
-
|
2162 |
-
|
2163 |
-
|
2164 |
-
|
2165 |
-
|
2166 |
-
|
2167 |
-
|
2168 |
-
|
2169 |
-
|
2170 |
-
|
2171 |
-
|
2172 |
-
|
2173 |
-
|
2174 |
-
|
2175 |
-
|
2176 |
-
|
2177 |
-
|
2178 |
-
|
2179 |
-
|
2180 |
-
|
2181 |
-
|
2182 |
-
|
2183 |
-
|
2184 |
-
|
2185 |
-
|
2186 |
-
|
2187 |
-
|
2188 |
-
|
2189 |
-
|
2190 |
-
|
2191 |
-
|
2192 |
-
|
2193 |
-
|
2194 |
-
|
2195 |
-
|
2196 |
-
|
2197 |
-
|
2198 |
-
|
2199 |
-
|
2200 |
-
|
2201 |
-
|
2202 |
-
|
2203 |
-
|
2204 |
-
|
2205 |
-
|
2206 |
-
|
2207 |
-
|
2208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2209 |
|
2210 |
|
2211 |
}
|
12 |
use WPDM\__\Session;
|
13 |
use WPDM\__\TempStorage;
|
14 |
|
15 |
+
class PackageController extends PackageTemplate {
|
16 |
+
|
17 |
+
public $ID;
|
18 |
+
public $package;
|
19 |
+
public $shortCodes;
|
20 |
+
public $packageData = [];
|
21 |
+
public $files = [];
|
22 |
+
public $restAPI;
|
23 |
+
public $templateDir;
|
24 |
+
|
25 |
+
|
26 |
+
function __construct( $ID = null ) {
|
27 |
+
parent::__construct();
|
28 |
+
|
29 |
+
$this->templateDir = __DIR__ . '/views/';
|
30 |
+
$this->shortCodes = new Shortcodes();
|
31 |
+
new Hooks();
|
32 |
+
|
33 |
+
new RestAPI();
|
34 |
+
|
35 |
+
global $post;
|
36 |
+
if ( ! $ID && is_object( $post ) && $post->post_type == 'wpdmpro' ) {
|
37 |
+
$ID = $post->ID;
|
38 |
+
}
|
39 |
+
$this->ID = $ID;
|
40 |
+
|
41 |
+
}
|
42 |
+
|
43 |
+
function prepare( $ID = null, $template = null, $template_type = 'page' ) {
|
44 |
+
global $post;
|
45 |
+
|
46 |
+
if ( ! $ID ) {
|
47 |
+
$ID = $this->ID;
|
48 |
+
}
|
49 |
+
if ( ! $ID && isset( $post->ID ) && get_post_type( $post ) == 'wpdmpro' ) {
|
50 |
+
$ID = $post->ID;
|
51 |
+
}
|
52 |
+
if ( ! $ID ) {
|
53 |
+
$this->packageData = array( 'error' => __( "ID missing!", "download-manager" ) );
|
54 |
+
|
55 |
+
return $this;
|
56 |
+
}
|
57 |
+
|
58 |
+
if ( ! is_object( $post ) || $post->ID != $ID ) {
|
59 |
+
$_post = get_post( $ID );
|
60 |
+
if ( get_class( $_post ) != 'WP_Post' ) {
|
61 |
+
return new \WP_Error( 'broke', __( "Invalid Package ID!", "download-manager" ) );
|
62 |
+
}
|
63 |
+
$post_vars = (array) $_post;
|
64 |
+
} else {
|
65 |
+
$post_vars = (array) $post;
|
66 |
+
}
|
67 |
+
|
68 |
+
$ID = $post_vars['ID'];
|
69 |
+
|
70 |
+
$post_vars['title'] = stripcslashes( $post_vars['post_title'] );
|
71 |
+
$post_vars['description'] = stripcslashes( $post_vars['post_content'] );
|
72 |
+
$post_vars['description'] = wpautop( stripslashes( $post_vars['description'] ) );
|
73 |
+
|
74 |
+
if ( ! has_shortcode( $post_vars['description'], 'wpdm_package' ) ) {
|
75 |
+
$post_vars['description'] = do_shortcode( stripslashes( $post_vars['description'] ) );
|
76 |
+
}
|
77 |
+
|
78 |
+
$post_vars['excerpt'] = wpautop( stripcslashes( wpdm_escs( $post_vars['post_excerpt'] ) ) );
|
79 |
+
$author = get_user_by( 'id', $post_vars['post_author'] );
|
80 |
+
if ( is_object( $author ) ) {
|
81 |
+
$post_vars['author_name'] = $author->display_name;
|
82 |
+
}
|
83 |
+
$post_vars['author_profile_url'] = get_author_posts_url( $post_vars['post_author'] );
|
84 |
+
if ( is_object( $author ) ) {
|
85 |
+
$post_vars['avatar_url'] = get_avatar_url( $author->user_email );
|
86 |
+
}
|
87 |
+
if ( is_object( $author ) ) {
|
88 |
+
$post_vars['avatar'] = get_avatar( $author->user_email, 96 );
|
89 |
+
}
|
90 |
+
$post_vars['author_package_count'] = count_user_posts( $post_vars['post_author'], "wpdmpro" );
|
91 |
+
|
92 |
+
$template_tags = $this->parseTemplate( $template, $ID, $template_type );
|
93 |
+
|
94 |
+
//Featured Image
|
95 |
+
$post_vars['preview'] = $post_vars['thumb'] = "";
|
96 |
+
if ( has_post_thumbnail( $ID ) ) {
|
97 |
+
$src = wp_get_attachment_image_src( get_post_thumbnail_id( $ID ), 'full', false );
|
98 |
+
$post_vars['preview'] = $src['0'];
|
99 |
+
$post_vars['featured_image'] = get_the_post_thumbnail( $ID, 'full' );
|
100 |
+
|
101 |
+
if ( in_array( 'thumb', $template_tags ) ) {
|
102 |
+
$post_vars['thumb'] = get_the_post_thumbnail( $ID );
|
103 |
+
}
|
104 |
+
}
|
105 |
+
if ( in_array( 'create_date', $template_tags ) ) {
|
106 |
+
$post_vars['create_date'] = get_the_date( '', $ID );
|
107 |
+
}
|
108 |
+
|
109 |
+
if ( in_array( 'update_date', $template_tags ) ) {
|
110 |
+
$post_vars['update_date'] = date_i18n( get_option( 'date_format' ), strtotime( $post_vars['post_modified'] ) );
|
111 |
+
}
|
112 |
+
|
113 |
+
if ( in_array( 'categories', $template_tags ) ) {
|
114 |
+
$post_vars['categories'] = get_the_term_list( $ID, 'wpdmcategory', '', ', ', '' );
|
115 |
+
}
|
116 |
+
|
117 |
+
if ( in_array( 'category', $template_tags ) ) {
|
118 |
+
$cats = get_the_terms( $ID, 'wpdmcategory' );
|
119 |
+
if ( is_array( $cats ) && count( $cats ) > 0 ) {
|
120 |
+
$post_vars['category'] = $cats[0]->name;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
$post_vars['comment_count'] = wp_count_comments( $ID )->approved;
|
125 |
+
|
126 |
+
if ( in_array( 'cats_class', $template_tags ) ) {
|
127 |
+
$cats = wp_get_post_terms( $ID, 'wpdmcategory' );
|
128 |
+
$post_vars['cats_class'] = "";
|
129 |
+
foreach ( $cats as $cat ) {
|
130 |
+
$post_vars['cats_class'] .= " wpdmcat-{$cat->id} {$cat->slug}";
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
$data = $this->metaData( $post_vars['ID'] );
|
135 |
+
|
136 |
+
if ( is_array( $data ) ) {
|
137 |
+
$post_vars = array_merge( $data, $post_vars );
|
138 |
+
}
|
139 |
+
|
140 |
+
if ( ! isset( $post_vars['files'] ) || ! is_array( $post_vars['files'] ) ) {
|
141 |
+
$post_vars['files'] = self::getFiles( $ID, true );
|
142 |
+
}
|
143 |
+
|
144 |
+
if ( in_array( 'file_count', $template_tags ) ) {
|
145 |
+
$post_vars['file_count'] = count( $post_vars['files'] );
|
146 |
+
}
|
147 |
+
|
148 |
+
if ( in_array( 'play_button', $template_tags ) ) {
|
149 |
+
$post_vars['play_button'] = self::audioPlayer( $post_vars );
|
150 |
+
}
|
151 |
+
|
152 |
+
|
153 |
+
$post_vars['link_label'] = isset( $post_vars['link_label'] ) ? esc_attr( $post_vars['link_label'] ) : esc_attr__( "Download", "download-manager" );
|
154 |
+
$post_vars['page_url'] = get_permalink( $post_vars['ID'] );
|
155 |
+
$post_vars['page_link'] = "<a href='" . $post_vars['page_url'] . "'>{$post_vars['title']}</a>";
|
156 |
+
$post_vars['page_url_qr'] = "<img class='wpdm-qr-code wpdm-qr-code{$post_vars['ID']}' style='max-width: 250px' src='http://chart.googleapis.com/chart?cht=qr&chs=450x450&choe=UTF-8&chld=H|0&chl={$post_vars['page_url']}' alt='{$post_vars['title']}' />";
|
157 |
+
|
158 |
+
|
159 |
+
if ( ! isset( $post_vars['btnclass'] ) ) {
|
160 |
+
$post_vars['btnclass'] = wpdm_download_button_style( null, $ID );
|
161 |
+
}
|
162 |
+
|
163 |
+
if ( in_array( 'tags', $template_tags ) ) {
|
164 |
+
$tags = wp_get_post_terms( $post_vars['ID'], 'wpdmtag' );
|
165 |
+
$taghtml = "";
|
166 |
+
if ( is_array( $tags ) ) {
|
167 |
+
foreach ( $tags as $tag ) {
|
168 |
+
$taghtml .= "<a class='btn btn-secondary btn-xs' style='margin:0 5px 5px 0' href=\""
|
169 |
+
. get_tag_link( $tag->term_id )
|
170 |
+
. "\"><i class='fa fa-tag'></i> " . $tag->name . "</a> ";
|
171 |
+
}
|
172 |
+
}
|
173 |
+
$post_vars['tags'] = $taghtml;
|
174 |
+
}
|
175 |
+
|
176 |
+
if ( in_array( 'file_ext', $template_tags ) ) {
|
177 |
+
$post_vars['files'] = isset( $post_vars['files'] ) && is_array( $post_vars['files'] ) ? $post_vars['files'] : self::getFiles( $ID );
|
178 |
+
if ( count( $post_vars['files'] ) > 1 ) {
|
179 |
+
$post_vars['file_ext'] = 'zip';
|
180 |
+
}
|
181 |
+
if ( is_array( $post_vars['files'] ) && count( $post_vars['files'] ) == 1 ) {
|
182 |
+
$tmpdata = $post_vars['files'];
|
183 |
+
$tmpdata = array_shift( $tmpdata );
|
184 |
+
$tmpdata = explode( ".", $tmpdata );
|
185 |
+
$post_vars['file_ext'] = end( $tmpdata );
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
if ( in_array( 'file_size', $template_tags ) ) {
|
190 |
+
$post_vars['file_size'] = self::Size( $post_vars['ID'] );
|
191 |
+
}
|
192 |
+
|
193 |
+
if ( in_array( 'audio_player_single', $template_tags ) ) {
|
194 |
+
$post_vars['audio_player_single'] = self::audioPlayer( $post_vars, true );
|
195 |
+
}
|
196 |
+
|
197 |
+
if ( array_intersect( $template_tags, array(
|
198 |
+
'youtube_player',
|
199 |
+
'youtube_thumb_0',
|
200 |
+
'youtube_thumb_1',
|
201 |
+
'youtube_thumb_2',
|
202 |
+
'youtube_thumb_3'
|
203 |
+
) ) ) {
|
204 |
+
$post_vars['files'] = isset( $post_vars['files'] ) && is_array( $post_vars['files'] ) ? $post_vars['files'] : self::getFiles( $ID );
|
205 |
+
$tmplfile = $post_vars['files'];
|
206 |
+
$tmpfile = is_array( $tmplfile ) && count( $tmplfile ) > 0 ? array_shift( $tmplfile ) : '';
|
207 |
+
if ( strpos( $tmpfile, 'youtu' ) ) {
|
208 |
+
if ( preg_match( '/youtu\.be\/([^\/]+)/', $tmpfile, $match ) ) {
|
209 |
+
$vid = $match[1];
|
210 |
+
} else if ( preg_match( '/watch\?v=([^\/]+)/', $tmpfile, $match ) ) {
|
211 |
+
$vid = $match[1];
|
212 |
+
}
|
213 |
+
if ( isset( $vid ) ) {
|
214 |
+
$post_vars['youtube_thumb_0'] = '<img src="https://img.youtube.com/vi/' . $vid . '/0.jpg" alt="Thumb 0" />';
|
215 |
+
$post_vars['youtube_thumb_1'] = '<img src="https://img.youtube.com/vi/' . $vid . '/1.jpg" alt="Thumb 1" />';
|
216 |
+
$post_vars['youtube_thumb_2'] = '<img src="https://img.youtube.com/vi/' . $vid . '/2.jpg" alt="Thumb 2" />';
|
217 |
+
$post_vars['youtube_thumb_3'] = '<img src="https://img.youtube.com/vi/' . $vid . '/3.jpg" alt="Thumb 3" />';
|
218 |
+
$post_vars['youtube_player'] = '<iframe width="1280" height="720" src="https://www.youtube.com/embed/' . $vid . '" frameborder="0" allowfullscreen></iframe>';
|
219 |
+
}
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
if ( array_intersect( array( 'file_type_icon', 'icon' ), $template_tags ) ) {
|
224 |
+
$post_vars['files'] = isset( $post_vars['files'] ) && is_array( $post_vars['files'] ) ? $post_vars['files'] : self::getFiles( $ID );
|
225 |
+
if ( is_array( $post_vars['files'] ) ) {
|
226 |
+
$tifn = $ifn = @end( $post_vars['files'] );
|
227 |
+
$ifn = @explode( '.', $ifn );
|
228 |
+
$ifn = @end( $ifn );
|
229 |
+
if ( strlen( $ifn ) > 4 && strstr( $tifn, "://" ) ) {
|
230 |
+
$ifn = 'web';
|
231 |
+
}
|
232 |
+
if ( strlen( $ifn ) > 4 && ! strstr( $tifn, "://" ) ) {
|
233 |
+
$ifn = 'unknown';
|
234 |
+
}
|
235 |
+
} else {
|
236 |
+
$ifn = 'unknown';
|
237 |
+
}
|
238 |
+
|
239 |
+
$post_vars['file_type_icon'] = '<img class="wpdm_icon" alt="' . __( "Icon", "download-manager" ) . '" src="' . FileSystem::fileTypeIcon( ( @count( $post_vars['files'] ) <= 1 ? $ifn : 'zip' ) ) . '" />';
|
240 |
+
|
241 |
+
if ( ! isset( $post_vars['icon'] ) || $post_vars['icon'] == '' ) {
|
242 |
+
$post_vars['icon'] = $post_vars['file_type_icon'];
|
243 |
+
} else if ( ! strpos( $post_vars['icon'], '://' ) ) {
|
244 |
+
$post_vars['icon'] = '<img class="wpdm_icon" alt="' . __( "Icon", "download-manager" ) . '" src="' . plugins_url( str_replace( 'download-manager/file-type-icons/', 'download-manager/assets/file-type-icons/', $post_vars['icon'] ) ) . '" />';
|
245 |
+
} else if ( ! strpos( $post_vars['icon'], ">" ) ) {
|
246 |
+
$post_vars['icon'] = '<img class="wpdm_icon" alt="' . __( "Icon", "download-manager" ) . '" src="' . str_replace( 'download-manager/file-type-icons/', 'download-manager/assets/file-type-icons/', $post_vars['icon'] ) . '" />';
|
247 |
+
}
|
248 |
+
|
249 |
+
}
|
250 |
+
|
251 |
+
|
252 |
+
$post_vars['link_label'] = apply_filters( 'wpdm_button_image', $post_vars['link_label'], $post_vars, $template_type );
|
253 |
+
|
254 |
+
$post_vars['link_label'] = $post_vars['link_label'] ? $post_vars['link_label'] : __( "Download", "download-manager" );
|
255 |
+
|
256 |
+
$post_vars['download_url'] = $this->getDownloadURL( $post_vars['ID'] );
|
257 |
+
$post_vars['download_link_popup'] =
|
258 |
+
$post_vars['download_link_extended'] =
|
259 |
+
$post_vars['download_link'] = (int) get_option( '__wpdm_mask_dlink', 1 ) == 1 ? "<a class='wpdm-download-link download-on-click {$post_vars['btnclass']}' rel='nofollow' href='#' data-downloadurl=\"{$post_vars['download_url']}\">{$post_vars['link_label']}</a>" : "<a class='wpdm-download-link {$post_vars['btnclass']}' rel='nofollow' href='{$post_vars['download_url']}'>{$post_vars['link_label']}</a>";
|
260 |
+
|
261 |
+
$limit_over = 0;
|
262 |
+
$alert_size = ( $template_type == 'link' ) ? 'alert-sm' : '';
|
263 |
+
|
264 |
+
$loginmsg = Messages::login_required( $post_vars['ID'] );
|
265 |
+
|
266 |
+
//Download limit is over
|
267 |
+
if ( self::userDownloadLimitExceeded( $post_vars['ID'] ) ) {
|
268 |
+
$limit_over = 1;
|
269 |
+
$limit_msg = Messages::download_limit_exceeded( $post_vars['ID'] );
|
270 |
+
$post_vars['download_url'] = '#';
|
271 |
+
$post_vars['link_label'] = $limit_msg;
|
272 |
+
$post_vars['download_link_popup'] =
|
273 |
+
$post_vars['download_link_extended'] =
|
274 |
+
$post_vars['download_link'] = $post_vars['link_label'];
|
275 |
+
} //Item is expired
|
276 |
+
else if ( isset( $post_vars['expire_date'] ) && $post_vars['expire_date'] != "" && strtotime( $post_vars['expire_date'] ) < time() ) {
|
277 |
+
$post_vars['download_url'] = '#';
|
278 |
+
$post_vars['link_label'] = __( "Download was expired on", "download-manager" ) . " " . date_i18n( get_option( 'date_format' ) . " h:i A", strtotime( $post_vars['expire_date'] ) );
|
279 |
+
$post_vars['download_link'] =
|
280 |
+
$post_vars['download_link_extended'] =
|
281 |
+
$post_vars['download_link_popup'] = "<div class='alert alert-warning {$alert_size}' data-title='" . __( "DOWNLOAD ERROR:", "download-manager" ) . "'>{$post_vars['link_label']}</div>";
|
282 |
+
} //Not available yet
|
283 |
+
else if ( isset( $post_vars['publish_date'] ) && $post_vars['publish_date'] != '' && strtotime( $post_vars['publish_date'] ) > time() ) {
|
284 |
+
$post_vars['download_url'] = '#';
|
285 |
+
$post_vars['link_label'] = __( "Download will be available from ", "download-manager" ) . " " . date_i18n( get_option( 'date_format' ) . " h:i A", strtotime( $post_vars['publish_date'] ) );
|
286 |
+
$post_vars['download_link'] =
|
287 |
+
$post_vars['download_link_extended'] =
|
288 |
+
$post_vars['download_link_popup'] = "<div class='alert alert-warning {$alert_size}' data-title='" . __( "DOWNLOAD ERROR:", "download-manager" ) . "'>{$post_vars['link_label']}</div>";
|
289 |
+
} //User is not allowed
|
290 |
+
else if ( is_user_logged_in() && ! self::userCanAccess( $post_vars['ID'] ) ) {
|
291 |
+
$post_vars['download_url'] = '#';
|
292 |
+
$post_vars['link_label'] = stripslashes( get_option( '__wpdm_permission_denied_msg' ) );
|
293 |
+
$post_vars['link_label'] = $post_vars['link_label'] !== '' ? $post_vars['link_label'] : __( 'You are not allowed to download.', 'download-manager' );
|
294 |
+
$post_vars['download_link'] =
|
295 |
+
$post_vars['download_link_extended'] =
|
296 |
+
$post_vars['download_link_popup'] = "<div class='alert alert-danger {$alert_size}' data-title='" . __( "DOWNLOAD ERROR:", "download-manager" ) . "'>{$post_vars['link_label']}</div>";
|
297 |
+
} //User is not logged in and guest access is not allowed
|
298 |
+
else if ( ! is_user_logged_in() && ! self::userCanAccess( $post_vars['ID'] ) ) {
|
299 |
+
$packurl = get_permalink( $post_vars['ID'] );
|
300 |
+
$loginform = WPDM()->user->login->form( array( 'redirect' => $packurl ) );
|
301 |
+
$post_vars['download_url'] = WPDM()->user->login->url( $_SERVER['REQUEST_URI'] );
|
302 |
+
$post_vars['download_link'] =
|
303 |
+
$post_vars['download_link_extended'] =
|
304 |
+
$post_vars['download_link_popup'] = stripcslashes( str_replace( array(
|
305 |
+
"[loginform]",
|
306 |
+
"[this_url]",
|
307 |
+
"[package_url]"
|
308 |
+
), array( $loginform, $_SERVER['REQUEST_URI'], $packurl ), $loginmsg ) );
|
309 |
+
$post_vars['download_link'] =
|
310 |
+
$post_vars['download_link_extended'] =
|
311 |
+
$post_vars['download_link_popup'] = get_option( '__wpdm_login_form', 0 ) == 1 ? $loginform : $post_vars['download_link'];
|
312 |
+
} //PACKAGE is locked
|
313 |
+
else if ( $this->isLocked( $post_vars['ID'] ) ) {
|
314 |
+
$post_vars['download_url'] = '#';
|
315 |
+
$post_vars['download_link'] = $post_vars['download_link_popup'] = "<a href='#unlock' class='wpdm-download-link wpdm-download-locked {$post_vars['btnclass']}' data-package='{$post_vars['ID']}'>{$post_vars['link_label']}</a>"; //self::activeLocks($post_vars);
|
316 |
+
$post_vars['download_link_extended'] = self::activeLocks( $post_vars['ID'], array( 'embed' => 1 ) );
|
317 |
+
//$post_vars['download_link_popup'] = self::activeLocks($post_vars, array('popstyle' => 'popup'));
|
318 |
+
}
|
319 |
+
|
320 |
+
if ( isset( $data['terms_lock'] ) && $data['terms_lock'] != 0 && ( ! function_exists( 'wpdmpp_effective_price' ) || wpdmpp_effective_price( $post_vars['ID'] ) == 0 ) && $limit_over == 0 && self::userCanAccess( $post_vars['ID'] ) ) {
|
321 |
+
//$data['terms_conditions'] = wpautop(strip_tags($data['terms_conditions'], "<p><br><a><strong><b><i>"));
|
322 |
+
/*$data['terms_conditions'] = wpautop(wpdm_escs(get_post_meta($post_vars['ID'], '__wpdm_terms_conditions', true)));
|
323 |
$data['terms_title'] = wpdm_escs(get_post_meta($post_vars['ID'], '__wpdm_terms_title', true));
|
324 |
$data['terms_title'] = !isset($data['terms_title']) || $data['terms_title'] == '' ? __("Terms and Conditions", 'download-manager') : sanitize_text_field($data['terms_title']);
|
325 |
$data['terms_check_label'] = !isset($data['terms_check_label']) || $data['terms_check_label'] == '' ? __("I Agree With Terms and Conditions", 'download-manager') : sanitize_text_field($data['terms_check_label']);
|
329 |
//$data['terms_conditions'] = wpautop(strip_tags($data['terms_conditions'], "<p><br><a><strong><b><i>"));
|
330 |
$data['terms_conditions'] = wpautop(wpdm_escs($data['terms_conditions']));*/
|
331 |
|
332 |
+
$terms_page = (int) get_post_meta( $ID, '__wpdm_terms_page', true );
|
333 |
+
$terms_title = get_post_meta( $ID, '__wpdm_terms_title', true );
|
334 |
+
$terms_conditions = get_post_meta( $ID, '__wpdm_terms_conditions', true );
|
335 |
+
if ( $terms_page ) {
|
336 |
+
$terms_page = get_post( $terms_page );
|
337 |
+
$terms_title = $terms_page->post_title;
|
338 |
+
$terms_conditions = $terms_page->post_content;
|
339 |
+
}
|
340 |
+
$terms_title = $terms_title !== '' ? $terms_title : __( "Terms and Conditions", 'download-manager' );
|
341 |
+
$terms_check_label = get_post_meta( $ID, '__wpdm_terms_check_label', true );
|
342 |
+
$terms_check_label = $terms_check_label ? $terms_check_label : __( "I Agree With Terms and Conditions", 'download-manager' );
|
343 |
+
|
344 |
+
$data['terms_title'] = $terms_title;
|
345 |
+
$data['terms_check_label'] = $terms_check_label;
|
346 |
+
$data['terms_conditions'] = $terms_conditions;
|
347 |
+
|
348 |
+
if ( ! self::isLocked( $post_vars ) ) {
|
349 |
+
$post_vars['download_link_popup'] = $post_vars['download_link'] = "<a href='#unlock' class='wpdm-download-link wpdm-download-locked {$post_vars['btnclass']}' data-package='{$post_vars['ID']}'>{$post_vars['link_label']}</a>";
|
350 |
+
}
|
351 |
+
|
352 |
+
$post_vars['download_link_extended'] = "<div class='panel panel-default card card terms-panel' style='margin: 0'><div class='panel-heading card-header'>{$terms_title}</div><div class='panel-body card-body' style='max-height: 200px;overflow: auto'>{$terms_conditions}</div><div class='panel-footer card-footer'><label><input data-pid='{$post_vars['ID']}' class='wpdm-checkbox terms_checkbox terms_checkbox_{$post_vars['ID']}' type='checkbox' onclick='jQuery(\".download_footer_{$post_vars['ID']}\").slideToggle();'> {$terms_check_label}</label></div><div class='panel-footer card-footer download_footer_{$post_vars['ID']}' style='display:none;'>{$post_vars['download_link_extended']}</div></div><script>jQuery(function($){ $('#wpdm-filelist-{$post_vars['ID']} .btn.inddl, #xfilelist .btn.inddl').attr('disabled', 'disabled'); });</script>";
|
353 |
+
|
354 |
+
}
|
355 |
+
|
356 |
+
if ( ! isset( $post_vars['formatted'] ) ) {
|
357 |
+
$post_vars['formatted'] = 0;
|
358 |
+
}
|
359 |
+
++ $post_vars['formatted'];
|
360 |
+
|
361 |
+
$post_vars['__template'] = $template;
|
362 |
+
$post_vars['__template_type'] = $template_type;
|
363 |
+
$post_vars = apply_filters( 'wpdm_after_prepare_package_data', $post_vars, $template_type );
|
364 |
+
|
365 |
+
$this->packageData = $post_vars;
|
366 |
+
|
367 |
+
foreach ( $post_vars as $key => $val ) {
|
368 |
+
try {
|
369 |
+
if ( preg_match( '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $key ) ) {
|
370 |
+
$this->{$key} = $val;
|
371 |
+
}
|
372 |
+
} catch ( \Exception $e ) {
|
373 |
+
}
|
374 |
+
}
|
375 |
+
|
376 |
+
return $this;
|
377 |
+
}
|
378 |
+
|
379 |
+
/**
|
380 |
+
* @usage Get all or any specific package info
|
381 |
+
*
|
382 |
+
* @param $ID
|
383 |
+
* @param null $meta
|
384 |
+
*
|
385 |
+
* @return mixed
|
386 |
+
*/
|
387 |
+
public static function get( $ID, $meta = null ) {
|
388 |
+
$ID = (int) $ID;
|
389 |
+
if ( $ID == 0 ) {
|
390 |
+
return null;
|
391 |
+
}
|
392 |
+
if ( $meta != null ) {
|
393 |
+
return get_post_meta( $ID, "__wpdm_" . $meta, true );
|
394 |
+
}
|
395 |
+
$p = new PackageController();
|
396 |
+
$package = $p->prepare( $ID );
|
397 |
+
|
398 |
+
return $package->packageData;
|
399 |
+
}
|
400 |
+
|
401 |
+
/**
|
402 |
+
* @usage Verify single file download option
|
403 |
+
*
|
404 |
+
* @param null $ID
|
405 |
+
*
|
406 |
+
* @return mixed
|
407 |
+
*/
|
408 |
+
public function isSingleFileDownloadAllowed( $ID = null ) {
|
409 |
+
global $post;
|
410 |
+
if ( ! $ID && $post->post_type == 'wpdmpro' ) {
|
411 |
+
$ID = $post->ID;
|
412 |
+
}
|
413 |
+
$global = get_option( '__wpdm_individual_file_download', 1 );
|
414 |
+
$package = get_post_meta( $ID, '__wpdm_individual_file_download', true );
|
415 |
+
$effective = $package == - 1 || $package == '' ? $global : $package;
|
416 |
+
|
417 |
+
return apply_filters( "wpdm_is_single_file_download_allowed", $effective, $ID );
|
418 |
+
}
|
419 |
+
|
420 |
+
/**
|
421 |
+
* @param $id
|
422 |
+
*
|
423 |
+
* @usage Returns the user roles who has access to specified package
|
424 |
+
* @return array|mixed
|
425 |
+
*/
|
426 |
+
public function allowedRoles( $id ) {
|
427 |
+
$roles = get_post_meta( $id, '__wpdm_access', true );
|
428 |
+
$roles = maybe_unserialize( $roles );
|
429 |
+
|
430 |
+
$cats = get_the_terms( $id, 'wpdmcategory' );
|
431 |
+
if ( ! is_array( $roles ) ) {
|
432 |
+
$roles = array();
|
433 |
+
}
|
434 |
+
if ( is_array( $cats ) ) {
|
435 |
+
foreach ( $cats as $cat ) {
|
436 |
+
$croles = WPDM()->categories->getAllowedRoles( $cat->term_id );
|
437 |
+
$roles = array_merge( $roles, $croles );
|
438 |
+
}
|
439 |
+
}
|
440 |
+
|
441 |
+
$roles = array_unique( $roles );
|
442 |
+
|
443 |
+
$roles = apply_filters( "wpdm_allowed_roles", $roles, $id );
|
444 |
+
if ( ! is_array( $roles ) ) {
|
445 |
+
$roles = array();
|
446 |
+
}
|
447 |
+
|
448 |
+
return $roles;
|
449 |
+
}
|
450 |
+
|
451 |
+
/**
|
452 |
+
* @usage Check if a package is locked or public
|
453 |
+
*
|
454 |
+
* @param $id
|
455 |
+
*
|
456 |
+
* @return bool
|
457 |
+
*/
|
458 |
+
public function isLocked( $package = null ) {
|
459 |
+
if ( ! $package ) {
|
460 |
+
$package = $this->ID;
|
461 |
+
}
|
462 |
+
if ( ! is_array( $package ) && (int) $package > 0 ) {
|
463 |
+
$id = $package;
|
464 |
+
$package = array();
|
465 |
+
$package['ID'] = $id;
|
466 |
+
$package['email_lock'] = get_post_meta( $id, '__wpdm_email_lock', true );
|
467 |
+
$package['password_lock'] = get_post_meta( $id, '__wpdm_password_lock', true );
|
468 |
+
$package['gplusone_lock'] = get_post_meta( $id, '__wpdm_gplusone_lock', true );
|
469 |
+
$package['tweet_lock'] = get_post_meta( $id, '__wpdm_tweet_lock', true );
|
470 |
+
$package['twitterfollow_lock'] = get_post_meta( $id, '__wpdm_twitterfollow_lock', true );
|
471 |
+
$package['facebooklike_lock'] = get_post_meta( $id, '__wpdm_facebooklike_lock', true );
|
472 |
+
$package['linkedin_lock'] = get_post_meta( $id, '__wpdm_linkedin_lock', true );
|
473 |
+
$package['captcha_lock'] = get_post_meta( $id, '__wpdm_captcha_lock', true );
|
474 |
+
} else {
|
475 |
+
$id = $package['ID'];
|
476 |
+
}
|
477 |
+
$lock = '';
|
478 |
+
$package = apply_filters( 'wpdm_custom_data', $package, $id );
|
479 |
+
if ( isset( $package['email_lock'] ) && (int) $package['email_lock'] == 1 ) {
|
480 |
+
$lock = 'locked';
|
481 |
+
}
|
482 |
+
if ( isset( $package['password_lock'] ) && (int) $package['password_lock'] == 1 ) {
|
483 |
+
$lock = 'locked';
|
484 |
+
}
|
485 |
+
if ( isset( $package['gplusone_lock'] ) && (int) $package['gplusone_lock'] == 1 ) {
|
486 |
+
$lock = 'locked';
|
487 |
+
}
|
488 |
+
if ( isset( $package['tweet_lock'] ) && (int) $package['tweet_lock'] == 1 ) {
|
489 |
+
$lock = 'locked';
|
490 |
+
}
|
491 |
+
if ( isset( $package['twitterfollow_lock'] ) && (int) $package['twitterfollow_lock'] == 1 ) {
|
492 |
+
$lock = 'locked';
|
493 |
+
}
|
494 |
+
if ( isset( $package['facebooklike_lock'] ) && (int) $package['facebooklike_lock'] == 1 ) {
|
495 |
+
$lock = 'locked';
|
496 |
+
}
|
497 |
+
if ( isset( $package['linkedin_lock'] ) && (int) $package['linkedin_lock'] == 1 ) {
|
498 |
+
$lock = 'locked';
|
499 |
+
}
|
500 |
+
if ( isset( $package['captcha_lock'] ) && (int) $package['captcha_lock'] == 1 ) {
|
501 |
+
$lock = 'locked';
|
502 |
+
}
|
503 |
+
|
504 |
+
if ( $lock !== 'locked' ) {
|
505 |
+
$lock = apply_filters( 'wpdm_check_lock', $lock, $id );
|
506 |
+
}
|
507 |
+
|
508 |
+
return ( $lock === 'locked' );
|
509 |
+
}
|
510 |
+
|
511 |
+
/**
|
512 |
+
* Check if a package with the given $ID is password protected
|
513 |
+
*
|
514 |
+
* @param $ID
|
515 |
+
*
|
516 |
+
* @return bool
|
517 |
+
*/
|
518 |
+
function isPasswordProtected( $ID ) {
|
519 |
+
$locked = (int) get_post_meta( $ID, '__wpdm_password_lock', true );
|
520 |
+
$password = get_post_meta( $ID, '__wpdm_password', true );
|
521 |
+
|
522 |
+
return $locked && $password ? $password : false;
|
523 |
+
}
|
524 |
+
|
525 |
+
/**
|
526 |
+
* @usage Check if current user has access to package or category
|
527 |
+
*
|
528 |
+
* @param $id
|
529 |
+
* @param string $type
|
530 |
+
*
|
531 |
+
* @return bool
|
532 |
+
*/
|
533 |
+
public function userCanAccess( $ID = null, $type = 'package' ) {
|
534 |
+
global $current_user;
|
535 |
+
$ID = $ID ? $ID : $this->ID;
|
536 |
+
if ( ! $ID ) {
|
537 |
+
return false;
|
538 |
+
}
|
539 |
+
if ( $type == 'package' ) {
|
540 |
+
$roles = $this->allowedRoles( $ID );
|
541 |
+
} else {
|
542 |
+
$roles = WPDM()->categories->getAllowedRoles( $ID );
|
543 |
+
}
|
544 |
+
|
545 |
+
if ( ! is_array( $roles ) ) {
|
546 |
+
$roles = array();
|
547 |
+
}
|
548 |
+
$matched = is_user_logged_in() ? array_intersect( $current_user->roles, $roles ) : array();
|
549 |
+
|
550 |
+
if ( $type === 'category' && count( $roles ) == 0 ) {
|
551 |
+
return true;
|
552 |
+
}
|
553 |
+
if ( in_array( 'guest', $roles ) ) {
|
554 |
+
return true;
|
555 |
+
}
|
556 |
+
if ( count( $matched ) > 0 ) {
|
557 |
+
return true;
|
558 |
+
}
|
559 |
+
|
560 |
+
return false;
|
561 |
+
|
562 |
+
}
|
563 |
+
|
564 |
+
/**
|
565 |
+
* @usage Check if current user has access to package or category based on roles
|
566 |
+
*
|
567 |
+
* @param $id
|
568 |
+
* @param string $type
|
569 |
+
*
|
570 |
+
* @return bool
|
571 |
+
*/
|
572 |
+
public function userHasAccess( $user_id, $ID, $type = 'package' ) {
|
573 |
+
|
574 |
+
$user = get_user_by( 'ID', $user_id );
|
575 |
+
|
576 |
+
if ( $type == 'package' ) {
|
577 |
+
$roles = $this->allowedRoles( $ID );
|
578 |
+
} else {
|
579 |
+
$roles = WPDM()->categories->getAllowedRoles( $ID );
|
580 |
+
}
|
581 |
+
|
582 |
+
if ( ! is_array( $roles ) ) {
|
583 |
+
$roles = array();
|
584 |
+
}
|
585 |
+
$matched = is_user_logged_in() ? array_intersect( $user->roles, $roles ) : array();
|
586 |
+
if ( $type === 'category' && count( $roles ) == 0 ) {
|
587 |
+
return true;
|
588 |
+
}
|
589 |
+
if ( in_array( 'guest', $roles ) ) {
|
590 |
+
return true;
|
591 |
+
}
|
592 |
+
if ( count( $matched ) > 0 ) {
|
593 |
+
return true;
|
594 |
+
}
|
595 |
+
|
596 |
+
return false;
|
597 |
+
|
598 |
+
}
|
599 |
+
|
600 |
+
/**
|
601 |
+
* @usage Check user's download limit
|
602 |
+
*
|
603 |
+
* @param $ID
|
604 |
+
*
|
605 |
+
* @return bool
|
606 |
+
*/
|
607 |
+
public static function userDownloadLimitExceeded( $ID ) {
|
608 |
+
global $current_user;
|
609 |
+
|
610 |
+
if ( is_user_logged_in() ) {
|
611 |
+
$index = $current_user->ID;
|
612 |
+
} else {
|
613 |
+
$index = $_SERVER['REMOTE_ADDR'];
|
614 |
+
}
|
615 |
+
|
616 |
+
$stock = (int) get_post_meta( $ID, '__wpdm_quota', true );
|
617 |
+
$download_count = (int) get_post_meta( $ID, '__wpdm_download_count', true );
|
618 |
+
|
619 |
+
$user_download_count = WPDM()->downloadHistory->userDownloadCount( $ID );
|
620 |
+
|
621 |
+
$download_limit_per_user = (int) get_post_meta( $ID, '__wpdm_download_limit_per_user', true );
|
622 |
+
|
623 |
+
if ( $download_limit_per_user > 0 && $user_download_count >= $download_limit_per_user ) {
|
624 |
+
return apply_filters( "wpdm_user_download_limit_exceeded", true, $ID );
|
625 |
+
}
|
626 |
+
|
627 |
+
$exceeded = false;
|
628 |
+
|
629 |
+
if ( $stock > 0 && $download_count >= $stock ) {
|
630 |
+
$exceeded = true;
|
631 |
+
};
|
632 |
+
|
633 |
+
$exceeded = apply_filters( "wpdm_user_download_limit_exceeded", $exceeded, $ID );
|
634 |
+
|
635 |
+
return $exceeded;
|
636 |
+
}
|
637 |
+
|
638 |
+
function userDownloadCount( $ID ) {
|
639 |
+
global $wpdb;
|
640 |
+
//$wpdb->
|
641 |
+
}
|
642 |
+
|
643 |
+
/**
|
644 |
+
* @usage Check if user is can download this package
|
645 |
+
*
|
646 |
+
* @param $ID
|
647 |
+
*
|
648 |
+
* @return bool
|
649 |
+
*/
|
650 |
+
public function userCanDownload( $ID ) {
|
651 |
+
return $this->userCanAccess( $ID ) && ! $this->userDownloadLimitExceeded( $ID );
|
652 |
+
}
|
653 |
+
|
654 |
+
/**
|
655 |
+
* @usage Count files in a package
|
656 |
+
*
|
657 |
+
* @param $id
|
658 |
+
*
|
659 |
+
* @return int
|
660 |
+
*/
|
661 |
+
public function fileCount( $ID ) {
|
662 |
+
|
663 |
+
$count = count( $this->getFiles( $ID, true ) );
|
664 |
+
|
665 |
+
return $count;
|
666 |
+
|
667 |
+
}
|
668 |
+
|
669 |
+
/**
|
670 |
+
* @usage Get list of attached files & all files inside attached dir with a package
|
671 |
+
*
|
672 |
+
* @param $ID
|
673 |
+
*
|
674 |
+
* @return array|mixed
|
675 |
+
*/
|
676 |
+
public function getFiles( $ID, $include_dir = false ) {
|
677 |
+
$files = maybe_unserialize( get_post_meta( $ID, '__wpdm_files', true ) );
|
678 |
+
if ( ! $files || ! is_array( $files ) ) {
|
679 |
+
$files = array();
|
680 |
+
}
|
681 |
+
foreach ( $files as &$file ) {
|
682 |
+
$file = trim( $file );
|
683 |
+
}
|
684 |
+
if ( $include_dir ) {
|
685 |
+
$package_dir = get_post_meta( $ID, '__wpdm_package_dir', true );
|
686 |
+
$package_dir = file_exists( $package_dir ) ? $package_dir : Crypt::decrypt( $package_dir );
|
687 |
+
if ( $package_dir != '' ) {
|
688 |
+
$package_dir = trailingslashit( $package_dir );
|
689 |
+
$package_dir = realpath( $package_dir );
|
690 |
+
if ( $package_dir ) {
|
691 |
+
$dfiles = FileSystem::scanDir( $package_dir, true, true, '', true );
|
692 |
+
$files += $dfiles;
|
693 |
+
}
|
694 |
+
}
|
695 |
+
}
|
696 |
+
$files = apply_filters( "wpdm_get_files", $files, $ID );
|
697 |
+
|
698 |
+
return $files;
|
699 |
+
}
|
700 |
+
|
701 |
+
/**
|
702 |
+
* @usage Create zip from attached files
|
703 |
+
*
|
704 |
+
* @param $ID
|
705 |
+
*
|
706 |
+
* @return mixed|string|\WP_Error
|
707 |
+
*/
|
708 |
+
public function zip( $ID ) {
|
709 |
+
$files = $this->getFiles( $ID );
|
710 |
+
$zipped = get_post_meta( $ID, "__wpdm_zipped_file", true );
|
711 |
+
if ( count( $files ) > 0 ) {
|
712 |
+
if ( $zipped == '' || ! file_exists( $zipped ) ) {
|
713 |
+
$zipped = UPLOAD_DIR . sanitize_file_name( get_the_title( $ID ) ) . '-' . $ID . '.zip';
|
714 |
+
$zipped = FileSystem::zipFiles( $files, $zipped );
|
715 |
+
|
716 |
+
return $zipped;
|
717 |
+
}
|
718 |
+
}
|
719 |
+
|
720 |
+
return new \WP_Error( 404, __( "No File Attached!", "download-manager" ) );
|
721 |
+
}
|
722 |
+
|
723 |
+
/**
|
724 |
+
* @usage Calculate package size
|
725 |
+
*
|
726 |
+
* @param $ID
|
727 |
+
* @param bool|false $recalculate
|
728 |
+
*
|
729 |
+
* @return bool|float|int|mixed|string
|
730 |
+
*/
|
731 |
+
public function size( $ID, $recalculate = false ) {
|
732 |
+
|
733 |
+
if ( get_post_type( $ID ) != 'wpdmpro' ) {
|
734 |
+
return false;
|
735 |
+
}
|
736 |
+
|
737 |
+
$size = get_post_meta( $ID, '__wpdm_package_size', true );
|
738 |
+
|
739 |
+
if ( $size != "" && ! $recalculate ) {
|
740 |
+
return $size;
|
741 |
+
}
|
742 |
+
|
743 |
+
$files = $this->getFiles( $ID );
|
744 |
+
|
745 |
+
$size = 0;
|
746 |
+
if ( is_array( $files ) ) {
|
747 |
+
foreach ( $files as $f ) {
|
748 |
+
$f = trim( $f );
|
749 |
+
if ( __::is_url( $f ) ) {
|
750 |
+
continue;
|
751 |
+
}
|
752 |
+
if ( file_exists( $f ) ) {
|
753 |
+
$size += @filesize( $f );
|
754 |
+
} else {
|
755 |
+
$size += @filesize( UPLOAD_DIR . $f );
|
756 |
+
}
|
757 |
+
}
|
758 |
+
}
|
759 |
+
|
760 |
+
update_post_meta( $ID, '__wpdm_package_size_b', $size );
|
761 |
+
$size = $size / 1024;
|
762 |
+
if ( $size > 1024 ) {
|
763 |
+
$size = number_format( $size / 1024, 2 ) . ' MB';
|
764 |
+
} else {
|
765 |
+
$size = number_format( $size, 2 ) . ' KB';
|
766 |
+
}
|
767 |
+
update_post_meta( $ID, '__wpdm_package_size', $size );
|
768 |
+
|
769 |
+
return $size;
|
770 |
+
}
|
771 |
+
|
772 |
+
/**
|
773 |
+
* @usage Generate play button for link template
|
774 |
+
*
|
775 |
+
* @param $package
|
776 |
+
* @param bool $return
|
777 |
+
* @param $style
|
778 |
+
*
|
779 |
+
* @return mixed|string|void
|
780 |
+
*/
|
781 |
+
public function audioPlayer( $package, $return = true, $style = 'primary btn-lg wpdm-btn-play-lg' ) {
|
782 |
+
|
783 |
+
$audiohtml = "";
|
784 |
+
|
785 |
+
if ( ! is_array( $package['files'] ) || count( $package['files'] ) == 0 ) {
|
786 |
+
return;
|
787 |
+
}
|
788 |
+
$audios = array();
|
789 |
+
$nonce = wp_create_nonce( $_SERVER['REQUEST_URI'] );
|
790 |
+
$audio = $audx = null;
|
791 |
+
foreach ( $package['files'] as $index => $file ) {
|
792 |
+
$realpath = file_exists( $file ) ? $file : UPLOAD_DIR . $file;
|
793 |
+
$filetype = wp_check_filetype( $realpath );
|
794 |
+
$tmpvar = explode( '/', $filetype['type'] );
|
795 |
+
if ( $tmpvar[0] == 'audio' ) {
|
796 |
+
$audio = $file;
|
797 |
+
$audx = $index;
|
798 |
+
break;
|
799 |
+
}
|
800 |
+
}
|
801 |
+
|
802 |
+
if ( $audio != null ) {
|
803 |
+
$song = FileSystem::mediaURL( $package['ID'], $audx, basename( $audio ) ); //home_url("/?wpdmdl={$package['ID']}&ind=".$audx."&play=".basename($audio));
|
804 |
+
$audiohtml = "<button data-player='wpdm-audio-player' data-song='{$song}' class='btn btn-{$style} wpdm-btn-play'><i class='fa fa-play'></i></button>";
|
805 |
+
$audiohtml = apply_filters( "wpdm_audio_play_button", $audiohtml, $song, $package, 0 );
|
806 |
+
}
|
807 |
+
|
808 |
+
if ( $return ) {
|
809 |
+
return $audiohtml;
|
810 |
+
}
|
811 |
+
|
812 |
+
echo $audiohtml;
|
813 |
+
|
814 |
+
}
|
815 |
+
|
816 |
+
/**
|
817 |
+
* @param $ID
|
818 |
+
* @param $files
|
819 |
+
* @param int $width
|
820 |
+
*
|
821 |
+
* @return string
|
822 |
+
*/
|
823 |
+
public static function videoPlayer( $ID, $files = null, $width = 800 ) {
|
824 |
+
|
825 |
+
if ( ! $files ) {
|
826 |
+
$files = WPDM()->package->getFiles( $ID );
|
827 |
+
}
|
828 |
+
|
829 |
+
$videos = array();
|
830 |
+
foreach ( $files as $index => $file ) {
|
831 |
+
$realpath = file_exists( $file ) ? $file : UPLOAD_DIR . $file;
|
832 |
+
$filetype = wp_check_filetype( $realpath );
|
833 |
+
$tmpvar = explode( '/', $filetype['type'] );
|
834 |
+
if ( $tmpvar[0] == 'video' ) {
|
835 |
+
$videos[] = $file;
|
836 |
+
$vidx[] = $index;
|
837 |
+
}
|
838 |
+
|
839 |
+
}
|
840 |
+
|
841 |
+
$videothumbs = "";
|
842 |
+
$mpvs = get_post_meta( $ID, '__wpdm_additional_previews', true );
|
843 |
+
$mmv = 0;
|
844 |
+
|
845 |
+
if ( is_array( $mpvs ) && count( $mpvs ) > 1 && count( $videos ) > 1 ) {
|
846 |
+
|
847 |
+
foreach ( $mpvs as $i => $mpv ) {
|
848 |
+
if ( $mmv < count( $videos ) ) {
|
849 |
+
//$url = self::expirableDownloadLink($ID, 3);
|
850 |
+
$ind = $vidx[ $i ]; //\WPDM_Crypt::Encrypt($videos[$mmv]);
|
851 |
+
//$video = $url . "&ind={$ind}&play=" . basename($videos[$mmv]);
|
852 |
+
$video = FileSystem::mediaURL( $ID, $ind, wpdm_basename( $videos[ $mmv ] ) );
|
853 |
+
|
854 |
+
$videothumbs .= "<a href='#' data-video='{$video}' class='__wpdm_playvideo'><img class='thumbnail' src='" . wpdm_dynamic_thumb( $mpv, array(
|
855 |
+
64,
|
856 |
+
64
|
857 |
+
) ) . "'/></a>";
|
858 |
+
}
|
859 |
+
$mmv ++;
|
860 |
+
}
|
861 |
+
}
|
862 |
+
|
863 |
+
$player_html = '';
|
864 |
+
if ( count( $videos ) > 0 ) {
|
865 |
+
//$url = self::expirableDownloadLink($ID, 10);
|
866 |
+
$ind = $vidx[0]; //\WPDM_Crypt::Encrypt($videos[0]);
|
867 |
+
//$video = $url . "&ind={$ind}&play=" . basename($videos[0]);
|
868 |
+
$video = FileSystem::mediaURL( $ID, $ind, wpdm_basename( $videos[0] ) );
|
869 |
+
|
870 |
+
$player_html = "<video id='__wpdm_videoplayer' class='thumbnail' width=\"{$width}\" controls controlsList='nodownload'><source src=\"{$video}\" type=\"video/mp4\">Your browser does not support HTML5 video.</video><div class='videothumbs'>{$videothumbs}</div>";
|
871 |
+
//if(!WPDM()->package->userCanAccess($ID)) $player_html = \WPDM\__\Messages::Error(stripslashes(get_option('wpdm_permission_msg')), -1);
|
872 |
+
}
|
873 |
+
|
874 |
+
$player_html = apply_filters( "wpdm_video_player_html", $player_html, $ID, $file, $width );
|
875 |
+
|
876 |
+
return $player_html;
|
877 |
+
}
|
878 |
+
|
879 |
+
/**
|
880 |
+
* @param $ID
|
881 |
+
* @param $files
|
882 |
+
* @param int $width
|
883 |
+
* @param int $height
|
884 |
+
*
|
885 |
+
* @return mixed|string
|
886 |
+
*/
|
887 |
+
public function productPreview( $ID, $files = null, $width = 800, $height = 600 ) {
|
888 |
+
if ( ! $files ) {
|
889 |
+
$files = WPDM()->package->getFiles( $ID );
|
890 |
+
}
|
891 |
+
$tfiles = $files;
|
892 |
+
$keys = array_keys( $files );
|
893 |
+
$ind = $keys[0];
|
894 |
+
$file = array_shift( $tfiles );
|
895 |
+
$realpath = file_exists( $file ) ? $file : UPLOAD_DIR . $file;
|
896 |
+
$filetype = wp_check_filetype( $realpath );
|
897 |
+
$type = explode( '/', $filetype['type'] );
|
898 |
+
$type = $type[1];
|
899 |
+
switch ( $type ) {
|
900 |
+
case 'mpeg':
|
901 |
+
case 'mp4':
|
902 |
+
return self::videoPlayer( $ID, $files, $width );
|
903 |
+
case 'png':
|
904 |
+
case 'jpg':
|
905 |
+
case 'jpeg':
|
906 |
+
return "<img src='" . FileSystem::imageThumbnail( $realpath, $width, $height ) . "' alt='" . get_the_title( $ID ) . "'/>";
|
907 |
+
case 'pdf':
|
908 |
+
$url = self::expirableDownloadLink( $ID, 1, 300 );
|
909 |
+
//$ind = \WPDM_Crypt::Encrypt($file);
|
910 |
+
$url .= "&ind={$ind}";
|
911 |
+
|
912 |
+
return FileSystem::docViewer( $url, $ID, 'pdf' );
|
913 |
+
default:
|
914 |
+
return '';
|
915 |
+
}
|
916 |
+
}
|
917 |
+
|
918 |
+
/**
|
919 |
+
* @usage Get All Custom Data of a Package
|
920 |
+
*
|
921 |
+
* @param $pid
|
922 |
+
*
|
923 |
+
* @return array
|
924 |
+
*/
|
925 |
+
public function metaData( $ID ) {
|
926 |
+
global $wpdb;
|
927 |
+
|
928 |
+
$metaValidate = [
|
929 |
+
'__wpdm_icon' => 'txt',
|
930 |
+
'__wpdm_view_count' => 'int',
|
931 |
+
'__wpdm_download_count' => 'int',
|
932 |
+
'__wpdm_link_label' => 'txt',
|
933 |
+
'__wpdm_version' => 'txt',
|
934 |
+
'__wpdm_quota' => 'int',
|
935 |
+
'__wpdm_access' => 'array',
|
936 |
+
'__wpdm_package_size' => 'txt',
|
937 |
+
'__wpdm_download_limit_per_user' => 'int',
|
938 |
+
'__wpdm_terms_lock' => 'int',
|
939 |
+
'__wpdm_publish_date' => 'txt',
|
940 |
+
'__wpdm_expire_date' => 'txt'
|
941 |
+
];
|
942 |
+
$metaKeys = array_keys( $metaValidate );
|
943 |
+
$metaData = $wpdb->get_results( "select * from {$wpdb->prefix}postmeta where meta_key in ('" . implode( '\',\'', $metaKeys ) . "') and post_id = '{$ID}'" );
|
944 |
+
|
945 |
+
$data = [];
|
946 |
+
if ( is_array( $metaData ) ) {
|
947 |
+
foreach ( $metaData as $metaDataRow ) {
|
948 |
+
$key = str_replace( "__wpdm_", "", $metaDataRow->meta_key );
|
949 |
+
if ( $key === 'publish_date' ) {
|
950 |
+
$key = 'avail_date';
|
951 |
+
$metaDataRow->meta_value = wp_date( get_option( 'date_format' ) . " " . get_option( 'time_format' ), strtotime( $metaDataRow->meta_value ) );
|
952 |
+
}
|
953 |
+
if ( $key === 'expire_date' ) {
|
954 |
+
$metaDataRow->meta_value = wp_date( get_option( 'date_format' ) . " " . get_option( 'time_format' ), strtotime( $metaDataRow->meta_value ) );
|
955 |
+
}
|
956 |
+
//if($metaValidate[$metaDataRow->meta_key] === 'array' && !is_array($metaDataRow->meta_value)) $metaDataRow->meta_value = unserialize($metaDataRow->meta_value);
|
957 |
+
//else
|
958 |
+
// $metaDataRow->meta_value = __::sanitize_var($metaDataRow->meta_value, $metaValidate[$metaDataRow->meta_key]);
|
959 |
+
$data[ $key ] = wpdm_sanitize_var( maybe_unserialize( $metaDataRow->meta_value ), $metaValidate[ $metaDataRow->meta_key ] );
|
960 |
+
}
|
961 |
+
}
|
962 |
+
unset( $metaData );
|
963 |
+
$data = apply_filters( 'wpdm_custom_data', $data, $ID );
|
964 |
+
if ( ! is_array( $data ) ) {
|
965 |
+
$data = [];
|
966 |
+
}
|
967 |
+
|
968 |
+
return $data;
|
969 |
+
}
|
970 |
+
|
971 |
+
/**
|
972 |
+
* @usage Generate download link of a package
|
973 |
+
*
|
974 |
+
* @param $package
|
975 |
+
* @param int $embed
|
976 |
+
* @param array $extras
|
977 |
+
*
|
978 |
+
* @return string
|
979 |
+
*/
|
980 |
+
function prepareDownloadLink( &$package, $embed = 0, $extras = array() ) {
|
981 |
+
global $wpdb, $current_user, $wpdm_download_icon, $wpdm_download_lock_icon, $btnclass;
|
982 |
+
if ( is_array( $extras ) ) {
|
983 |
+
extract( $extras );
|
984 |
+
}
|
985 |
+
$data = '';
|
986 |
+
|
987 |
+
$package['link_url'] = home_url( '/?download=1&' );
|
988 |
+
$package['link_label'] = ! isset( $package['link_label'] ) || $package['link_label'] == '' ? __( "Download", "download-manager" ) : $package['link_label'];
|
989 |
+
|
990 |
+
//Change link label using a button image
|
991 |
+
$template_type = isset( $template_type ) ? $template_type : 'link';
|
992 |
+
$package['link_label'] = apply_filters( 'wpdm_button_image', $package['link_label'], $package, $template_type );
|
993 |
+
|
994 |
+
|
995 |
+
$package['download_url'] = wpdm_download_url( $package );
|
996 |
+
if ( wpdm_is_download_limit_exceed( $package['ID'] ) ) {
|
997 |
+
$limit_msg = Messages::download_limit_exceeded( $package['ID'] );
|
998 |
+
$package['download_url'] = '#';
|
999 |
+
$package['link_label'] = $limit_msg;
|
1000 |
+
}
|
1001 |
+
if ( isset( $package['expire_date'] ) && $package['expire_date'] != "" && strtotime( $package['expire_date'] ) < time() ) {
|
1002 |
+
$package['download_url'] = '#';
|
1003 |
+
$package['link_label'] = apply_filters( "wpdm_download_expired_message", __( "Download was expired on", "download-manager" ) . " " . date_i18n( get_option( 'date_format' ) . " h:i A", strtotime( $package['expire_date'] ) ), $package );
|
1004 |
+
$package['download_link'] = $vars['download_link_extended'] = $vars['download_link_popup'] = "<a href='#'>{$package['link_label']}</a>";
|
1005 |
+
|
1006 |
+
return "<div class='alert alert-warning'><b>" . __( "Download:", "download-manager" ) . "</b><br/>{$package['link_label']}</div>";
|
1007 |
+
}
|
1008 |
+
|
1009 |
+
if ( isset( $package['publish_date'] ) && $package['publish_date'] != '' && strtotime( $package['publish_date'] ) > time() ) {
|
1010 |
+
$package['download_url'] = '#';
|
1011 |
+
$package['link_label'] = apply_filters( "wpdm_download_availability_message", __( "Download will be available from ", "download-manager" ) . " " . date_i18n( get_option( 'date_format' ) . " h:i A", strtotime( $package['publish_date'] ) ), $package );
|
1012 |
+
$package['download_link'] = $vars['download_link_extended'] = $vars['download_link_popup'] = "<a href='#'>{$package['link_label']}</a>";
|
1013 |
+
|
1014 |
+
return "<div class='alert alert-warning'><b>" . __( "Download:", "download-manager" ) . "</b><br/>{$package['link_label']}</div>";
|
1015 |
+
}
|
1016 |
+
|
1017 |
+
$link_label = isset( $package['link_label'] ) ? $package['link_label'] : __( "Download", "download-manager" );
|
1018 |
+
|
1019 |
+
$package['access'] = wpdm_allowed_roles( $package['ID'] );
|
1020 |
+
|
1021 |
+
if ( $package['download_url'] != '#' ) {
|
1022 |
+
$package['download_link'] = $vars['download_link_extended'] = $vars['download_link_popup'] = "<a class='wpdm-download-link {$btnclass}' rel='nofollow' href='#' onclick=\"location.href='{$package['download_url']}';return false;\"><i class='$wpdm_download_icon'></i>{$link_label}</a>";
|
1023 |
+
} else {
|
1024 |
+
$package['download_link'] = $vars['download_link_extended'] = $vars['download_link_popup'] = "<div class='alert alert-warning'><b>" . __( "Download:", "download-manager" ) . "</b><br/>{$link_label}</div>";
|
1025 |
+
}
|
1026 |
+
$caps = array_keys( $current_user->caps );
|
1027 |
+
$role = array_shift( $caps );
|
1028 |
+
|
1029 |
+
$matched = ( is_array( @maybe_unserialize( $package['access'] ) ) && is_user_logged_in() ) ? array_intersect( $current_user->roles, @maybe_unserialize( $package['access'] ) ) : array();
|
1030 |
+
|
1031 |
+
$skiplink = 0;
|
1032 |
+
|
1033 |
+
if ( is_user_logged_in() && count( $matched ) <= 0 && ! @in_array( 'guest', @maybe_unserialize( $package['access'] ) ) ) {
|
1034 |
+
$package['download_url'] = "#";
|
1035 |
+
$package['download_link'] = $vars['download_link_extended'] = $vars['download_link_popup'] = stripslashes( get_option( '__wpdm_permission_denied_msg' ) );
|
1036 |
+
$package = apply_filters( 'download_link', $package );
|
1037 |
+
if ( get_option( '_wpdm_hide_all', 0 ) == 1 ) {
|
1038 |
+
$package['download_link'] = $package['download_link_extended'] = 'blocked';
|
1039 |
+
}
|
1040 |
+
|
1041 |
+
return $package['download_link'];
|
1042 |
+
}
|
1043 |
+
if ( ! @in_array( 'guest', @maybe_unserialize( $package['access'] ) ) && ! is_user_logged_in() ) {
|
1044 |
+
|
1045 |
+
$loginform = wpdm_login_form( array( 'redirect' => get_permalink( $package['ID'] ) ) );
|
1046 |
+
if ( get_option( '_wpdm_hide_all', 0 ) == 1 ) {
|
1047 |
+
return 'loginform';
|
1048 |
+
}
|
1049 |
+
$package['download_url'] = $vars['download_link_extended'] = $vars['download_link_popup'] = home_url( '/wp-login.php?redirect_to=' . urlencode( $_SERVER['REQUEST_URI'] ) );
|
1050 |
+
$loginmsg = Messages::login_required( $package['ID'] );
|
1051 |
+
$package['download_link'] = stripcslashes( str_replace( array(
|
1052 |
+
"[loginform]",
|
1053 |
+
"[this_url]",
|
1054 |
+
"[package_url]"
|
1055 |
+
), array( $loginform, $_SERVER['REQUEST_URI'], get_permalink( $package['ID'] ) ), $loginmsg ) );
|
1056 |
+
|
1057 |
+
return get_option( '__wpdm_login_form', 0 ) == 1 ? $loginform : $package['download_link'];
|
1058 |
+
|
1059 |
+
}
|
1060 |
|
1061 |
+
$package = apply_filters( 'download_link', $package );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1062 |
|
1063 |
+
$unqid = uniqid();
|
1064 |
|
1065 |
+
if ( ! isset( $package['quota'] ) || ( isset( $package['quota'] ) && $package['quota'] > 0 && $package['quota'] > $package['download_count'] ) || $package['quota'] == 0 ) {
|
1066 |
+
$lock = 0;
|
1067 |
|
1068 |
+
if ( isset( $package['password_lock'] ) && (int) $package['password_lock'] == 1 && $package['password'] != '' ) {
|
1069 |
+
$lock = 'locked';
|
1070 |
+
$data = PackageLocks::AskPassword( $package );
|
1071 |
+
}
|
1072 |
|
1073 |
|
1074 |
+
$sociallock = "";
|
1075 |
|
1076 |
+
if ( isset( $package['email_lock'] ) && (int) $package['email_lock'] == 1 ) {
|
1077 |
+
$data .= PackageLocks::AskEmail( $package );
|
1078 |
+
$lock = 'locked';
|
1079 |
+
}
|
1080 |
|
1081 |
+
if ( isset( $package['linkedin_lock'] ) && (int) $package['linkedin_lock'] == 1 ) {
|
1082 |
+
$lock = 'locked';
|
1083 |
+
$sociallock .= PackageLocks::LinkedInShare( $package );
|
1084 |
|
1085 |
+
}
|
1086 |
|
1087 |
+
if ( isset( $package['twitterfollow_lock'] ) && (int) $package['twitterfollow_lock'] == 1 ) {
|
1088 |
+
$lock = 'locked';
|
1089 |
+
$sociallock .= PackageLocks::TwitterFollow( $package );
|
1090 |
|
1091 |
+
}
|
1092 |
|
1093 |
+
if ( isset( $package['gplusone_lock'] ) && (int) $package['gplusone_lock'] == 1 ) {
|
1094 |
+
$lock = 'locked';
|
1095 |
+
$sociallock .= PackageLocks::GooglePlusOne( $package, true );
|
1096 |
|
1097 |
+
}
|
1098 |
|
1099 |
+
if ( isset( $package['tweet_lock'] ) && (int) $package['tweet_lock'] == 1 ) {
|
1100 |
+
$lock = 'locked';
|
1101 |
+
$sociallock .= PackageLocks::Tweet( $package );
|
1102 |
|
1103 |
+
}
|
1104 |
|
1105 |
+
if ( isset( $package['facebooklike_lock'] ) && (int) $package['facebooklike_lock'] == 1 ) {
|
1106 |
+
$lock = 'locked';
|
1107 |
+
$sociallock .= PackageLocks::FacebookLike( $package, true );
|
1108 |
|
1109 |
+
}
|
1110 |
|
1111 |
|
1112 |
+
if ( isset( $package['captcha_lock'] ) && (int) $package['captcha_lock'] == 1 ) {
|
1113 |
+
$lock = 'locked';
|
1114 |
+
$sociallock .= PackageLocks::reCaptchaLock( $package, true );
|
1115 |
|
1116 |
+
}
|
1117 |
|
1118 |
+
$extralocks = '';
|
1119 |
+
$extralocks = apply_filters( "wpdm_download_lock", $extralocks, $package );
|
1120 |
|
1121 |
+
if ( is_array( $extralocks ) && $extralocks['lock'] === 'locked' ) {
|
1122 |
|
1123 |
+
if ( isset( $extralocks['type'] ) && $extralocks['type'] == 'social' ) {
|
1124 |
+
$sociallock .= $extralocks['html'];
|
1125 |
+
} else {
|
1126 |
+
$data .= $extralocks['html'];
|
1127 |
+
}
|
1128 |
|
1129 |
+
$lock = 'locked';
|
1130 |
+
}
|
1131 |
|
1132 |
+
if ( $sociallock != "" ) {
|
1133 |
+
$data .= "<div class='panel panel-default card card-default'><div class='panel-heading card-header'>" . __( "Download", "download-manager" ) . "</div><div class='panel-body card-body wpdm-social-locks text-center'>{$sociallock}</div></div>";
|
1134 |
+
}
|
1135 |
|
1136 |
+
if ( $lock === 'locked' ) {
|
1137 |
+
$popstyle = isset( $popstyle ) && in_array( $popstyle, array(
|
1138 |
+
'popup',
|
1139 |
+
'pop-over'
|
1140 |
+
) ) ? $popstyle : 'pop-over';
|
1141 |
+
if ( $embed == 1 ) {
|
1142 |
+
$adata = "</strong>{$data}";
|
1143 |
+
} else {
|
1144 |
+
//$dataattrs = $popstyle == 'pop-over'? 'data-title="'.__( "Download" , "download-manager" ).' ' . $package['title'] . '"' : 'data-toggle="modal" data-target="#pkg_' . $package['ID'] . "_" . $unqid . '"';
|
1145 |
+
$adata = '<a href="#pkg_' . $package['ID'] . "_" . $unqid . '" data-trigger="manual" data-package="' . $package['ID'] . '" class="wpdm-download-link wpdm-download-locked ' . $popstyle . ' ' . $btnclass . '"><i class=\'' . $wpdm_download_lock_icon . '\'></i>' . $package['link_label'] . '</a>';
|
1146 |
|
1147 |
// if ($popstyle == 'pop-over') {
|
1148 |
// if(!get_option('__wpdm_ajax_popup', false))
|
1151 |
// else
|
1152 |
// $adata .= '<div class="modal fade" role="modal" id="pkg_' . $package['ID'] . "_" . $unqid . '"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><strong style="margin:0px;font-size:12pt">' . __('Download') . '</strong></div><div class="modal-body">' . $data . '</div><div class="modal-footer text-right"><button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Close</button></div></div></div></div>';
|
1153 |
|
1154 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1155 |
|
1156 |
+
$data = $adata;
|
1157 |
+
}
|
1158 |
+
if ( $lock !== 'locked' ) {
|
|
|
|
|
1159 |
|
1160 |
+
$data = $package['download_link'];
|
1161 |
|
|
|
|
|
|
|
|
|
|
|
1162 |
|
1163 |
+
}
|
1164 |
+
} else {
|
1165 |
+
$data = Messages::download_limit_exceeded( $package['ID'] );
|
1166 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1167 |
|
|
|
1168 |
|
1169 |
+
//return str_replace(array("\r","\n"),"",$data);
|
1170 |
+
return $data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1171 |
|
1172 |
+
}
|
1173 |
|
1174 |
+
private static function activeLocks( $ID, $params = array( 'embed' => 0, 'popstyle' => 'pop-over' ) ) {
|
1175 |
|
1176 |
+
$embed = isset( $params['embed'] ) ? $params['embed'] : 0;
|
1177 |
+
$template_type = isset( $params['template_type'] ) ? $params['template_type'] : 'link';
|
1178 |
+
$popstyle = isset( $params['popstyle'] ) ? $params['popstyle'] : 'pop-over';
|
1179 |
|
1180 |
+
$package = array(
|
1181 |
+
'ID' => $ID,
|
1182 |
+
'password' => get_post_meta( $ID, '__wpdm_password', true ),
|
1183 |
+
'password_lock' => get_post_meta( $ID, '__wpdm_password_lock', true ),
|
1184 |
+
'email_lock' => get_post_meta( $ID, '__wpdm_email_lock', true ),
|
1185 |
+
'linkedin_lock' => get_post_meta( $ID, '__wpdm_linkedin_lock', true ),
|
1186 |
+
'twitterfollow_lock' => get_post_meta( $ID, '__wpdm_twitterfollow_lock', true ),
|
1187 |
+
'gplusone_lock' => get_post_meta( $ID, '__wpdm_gplusone_lock', true ),
|
1188 |
+
'tweet_lock' => get_post_meta( $ID, '__wpdm_tweet_lock', true ),
|
1189 |
+
'facebooklike_lock' => get_post_meta( $ID, '__wpdm_facebooklike_lock', true ),
|
1190 |
+
'captcha_lock' => get_post_meta( $ID, '__wpdm_captcha_lock', true ),
|
1191 |
+
);
|
1192 |
|
1193 |
+
$package = apply_filters( 'wpdm_before_apply_locks', $package );
|
1194 |
+
$lock = $data = "";
|
1195 |
+
$unqid = uniqid();
|
1196 |
|
1197 |
+
if ( isset( $package['password_lock'] ) && (int) $package['password_lock'] == 1 && $package['password'] != '' ) {
|
1198 |
+
$lock = 'locked';
|
1199 |
+
$data = PackageLocks::AskPassword( $package );
|
1200 |
+
}
|
1201 |
|
1202 |
+
$sociallock = "";
|
|
|
1203 |
|
1204 |
+
if ( isset( $package['email_lock'] ) && (int) $package['email_lock'] == 1 ) {
|
1205 |
+
$data .= PackageLocks::AskEmail( $package );
|
1206 |
+
$lock = 'locked';
|
1207 |
+
}
|
|
|
|
|
1208 |
|
1209 |
+
if ( isset( $package['linkedin_lock'] ) && (int) $package['linkedin_lock'] == 1 ) {
|
1210 |
+
$lock = 'locked';
|
1211 |
+
$sociallock .= PackageLocks::LinkedInShare( $package );
|
1212 |
|
1213 |
+
}
|
|
|
|
|
|
|
|
|
1214 |
|
1215 |
+
if ( isset( $package['twitterfollow_lock'] ) && (int) $package['twitterfollow_lock'] == 1 ) {
|
1216 |
+
$lock = 'locked';
|
1217 |
+
$sociallock .= PackageLocks::TwitterFollow( $package );
|
|
|
|
|
1218 |
|
1219 |
+
}
|
1220 |
|
1221 |
+
if ( isset( $package['gplusone_lock'] ) && (int) $package['gplusone_lock'] == 1 ) {
|
1222 |
+
$lock = 'locked';
|
1223 |
+
$sociallock .= PackageLocks::GooglePlusOne( $package, true );
|
1224 |
|
1225 |
+
}
|
|
|
|
|
|
|
|
|
1226 |
|
1227 |
+
if ( isset( $package['tweet_lock'] ) && (int) $package['tweet_lock'] == 1 ) {
|
1228 |
+
$lock = 'locked';
|
1229 |
+
$sociallock .= PackageLocks::Tweet( $package );
|
1230 |
|
1231 |
+
}
|
|
|
|
|
|
|
1232 |
|
1233 |
+
if ( isset( $package['facebooklike_lock'] ) && (int) $package['facebooklike_lock'] == 1 ) {
|
1234 |
+
$lock = 'locked';
|
1235 |
+
$sociallock .= PackageLocks::FacebookLike( $package, true );
|
1236 |
|
1237 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1238 |
|
|
|
|
|
1239 |
|
1240 |
+
$extralocks = '';
|
1241 |
+
$extralocks = apply_filters( "wpdm_download_lock", $extralocks, $package );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1242 |
|
1243 |
+
if ( is_array( $extralocks ) && $extralocks['lock'] === 'locked' ) {
|
1244 |
|
1245 |
+
if ( isset( $extralocks['type'] ) && $extralocks['type'] == 'social' ) {
|
1246 |
+
$sociallock .= $extralocks['html'];
|
1247 |
+
} else {
|
1248 |
+
$data .= $extralocks['html'];
|
1249 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1250 |
|
1251 |
+
$lock = 'locked';
|
1252 |
+
}
|
1253 |
|
1254 |
+
if ( $sociallock !== "" ) {
|
1255 |
+
$socdesc = get_option( '_wpdm_social_lock_panel_desc', '' );
|
1256 |
+
$socdesc = $socdesc !== '' ? "<p>{$socdesc}</p>" : "";
|
1257 |
+
$data .= "<div class='panel panel-default card'><div class='panel-heading card-header'>" . get_option( '_wpdm_social_lock_panel_title', 'Like or Share to Download' ) . "</div><div class='panel-body card-body wpdm-social-locks text-center'>{$socdesc}{$sociallock}</div></div>";
|
1258 |
+
}
|
1259 |
|
1260 |
|
1261 |
+
if ( isset( $package['captcha_lock'] ) && (int) $package['captcha_lock'] == 1 ) {
|
1262 |
+
$lock = 'locked';
|
1263 |
+
$captcha = PackageLocks::reCaptchaLock( $package, true );
|
1264 |
+
$data .= $captcha; //"<div class='panel panel-default card'><div class='panel-heading card-header'>" . __("Verify CAPTCHA to Download", "download-manager") . "</div><div class='panel-body card-body wpdm-social-locks text-center'>{$captcha}</div></div>";
|
1265 |
+
}
|
1266 |
|
1267 |
+
if ( $lock === 'locked' ) {
|
1268 |
+
$popstyle = isset( $popstyle ) && in_array( $popstyle, array(
|
1269 |
+
'popup',
|
1270 |
+
'pop-over'
|
1271 |
+
) ) ? $popstyle : 'pop-over';
|
1272 |
+
if ( $embed == 1 ) {
|
1273 |
+
$adata = "</strong>{$data}";
|
1274 |
+
} else {
|
1275 |
+
$link_label = get_post_meta( $ID, '__wpdm_link_label', true );
|
1276 |
+
$link_label = trim( $link_label ) ? $link_label : __( "Download", "download-manager" );
|
1277 |
+
$style = wpdm_download_button_style( ( $template_type === 'page' ), $ID );
|
1278 |
+
$style = isset( $params['btnclass'] ) && $params['btnclass'] !== '' ? $params['btnclass'] : $style;
|
1279 |
+
$adata = '<a href="#pkg_' . $ID . "_" . $unqid . '" data-package="' . $ID . '" data-trigger="manual" class="wpdm-download-link wpdm-download-locked ' . $style . '">' . $link_label . '</a>';
|
1280 |
|
1281 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1282 |
|
1283 |
+
$data = $adata;
|
1284 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1285 |
|
1286 |
+
return $data;
|
1287 |
+
}
|
1288 |
|
|
|
|
|
|
|
|
|
|
|
1289 |
|
1290 |
+
/**
|
1291 |
+
* @usage Generate download link of a package
|
1292 |
+
*
|
1293 |
+
* @param $package
|
1294 |
+
* @param int $embed
|
1295 |
+
* @param array $extras
|
1296 |
+
*
|
1297 |
+
* @return string
|
1298 |
+
*/
|
1299 |
+
public function downloadLink( $ID, $embed = 0, $extras = array() ) {
|
1300 |
+
global $wpdb, $current_user, $wpdm_download_icon, $wpdm_download_lock_icon;
|
1301 |
+
if ( is_array( $extras ) ) {
|
1302 |
+
extract( $extras );
|
1303 |
+
}
|
1304 |
+
$data = '';
|
1305 |
+
|
1306 |
+
$template_type = isset( $extras['template_type'] ) ? $extras['template_type'] : 'page';
|
1307 |
|
1308 |
+
//$package = self::get($ID);
|
1309 |
+
|
1310 |
+
$link_label = get_post_meta( $ID, '__wpdm_link_label', true );
|
1311 |
+
$link_label = ( trim( $link_label ) === '' ) ? __( "Download", "download-manager" ) : $link_label;
|
1312 |
|
1313 |
+
$template_type = isset( $template_type ) ? $template_type : 'link';
|
1314 |
+
$link_label = apply_filters( "wpdm_link_label", $link_label, $ID, $template_type );
|
1315 |
+
|
1316 |
+
$loginmsg = Messages::login_required( $ID );
|
1317 |
+
|
1318 |
+
$download_url = $this->getDownloadURL( $ID );
|
1319 |
+
|
1320 |
+
$limit_over = 0;
|
1321 |
+
$alert_size = ( $template_type == 'link' ) ? 'alert-sm' : '';
|
1322 |
+
|
1323 |
+
if ( self::userDownloadLimitExceeded( $ID ) ) {
|
1324 |
+
$limit_msg = Messages::download_limit_exceeded( $ID );
|
1325 |
+
$download_url = '#';
|
1326 |
+
$link_label = $limit_msg;
|
1327 |
+
$limit_over = 1;
|
1328 |
+
}
|
1329 |
+
|
1330 |
+
$expired = get_post_meta( $ID, '__wpdm_expire_date', true );
|
1331 |
+
$publish = get_post_meta( $ID, '__wpdm_publish_date', true );
|
1332 |
+
|
1333 |
+
if ( $expired !== "" && strtotime( $expired ) < time() ) {
|
1334 |
+
$download_url = '#';
|
1335 |
+
$link_label = __( "Download was expired on", "download-manager" ) . " " . date_i18n( get_option( 'date_format' ) . " h:i A", strtotime( $expired ) );
|
1336 |
+
|
1337 |
+
return "<div class='alert alert-warning {$alert_size}' data-title='" . __( "DOWNLOAD ERROR:", "download-manager" ) . "'>{$link_label}</div>";
|
1338 |
+
}
|
1339 |
+
|
1340 |
+
if ( $publish !== "" && strtotime( $publish ) > time() ) {
|
1341 |
+
$download_url = '#';
|
1342 |
+
$link_label = __( "Download will be available from ", "download-manager" ) . " " . date_i18n( get_option( 'date_format' ) . " h:i A", strtotime( $publish ) );
|
1343 |
+
|
1344 |
+
return "<div class='alert alert-warning {$alert_size}' data-title='" . __( "DOWNLOAD ERROR:", "download-manager" ) . "'>{$link_label}</div>";
|
1345 |
+
}
|
1346 |
+
|
1347 |
+
|
1348 |
+
$style = wpdm_download_button_style( ( $template_type === 'page' ), $ID );
|
1349 |
+
$style = isset( $btnclass ) && $btnclass !== '' ? $btnclass : $style;
|
1350 |
+
|
1351 |
+
if ( $download_url != '#' ) {
|
1352 |
+
$download_link = $download_link_extended = $download_link_popup = (int) get_option( '__wpdm_mask_dlink', 1 ) === 1 ? "<a class='wpdm-download-link download-on-click {$style}' rel='nofollow' href='#' data-downloadurl=\"{$download_url}\">{$link_label}</a>" : "<a class='wpdm-download-link {$style}' rel='nofollow' href='{$download_url}'>{$link_label}</a>";
|
1353 |
+
} //$download_link = $download_link_extended = $download_link_popup = (int)get_option('__wpdm_mask_dlink', 1) === 1 ? "<a class='wpdm-download-link {$style}' rel='nofollow' href='#' onclick=\"location.href='{$download_url}';return false;\">{$link_label}</a>" : "<a class='wpdm-download-link {$style}' rel='nofollow' href='{$download_url}'>{$link_label}</a>";
|
1354 |
+
else {
|
1355 |
+
$download_link = "<div class='alert alert-warning {$alert_size}' data-title='" . __( "DOWNLOAD ERROR:", "download-manager" ) . "'>{$link_label}</div>";
|
1356 |
+
}
|
1357 |
+
|
1358 |
+
|
1359 |
+
$access = self::allowedRoles( $ID );
|
1360 |
+
if ( ! is_array( $access ) ) {
|
1361 |
+
$access = array();
|
1362 |
+
}
|
1363 |
+
$matched = ( is_array( $access ) && is_user_logged_in() ) ? array_intersect( $current_user->roles, $access ) : array();
|
1364 |
+
if ( ! $matched ) {
|
1365 |
+
$matched = [];
|
1366 |
+
}
|
1367 |
+
|
1368 |
+
$skiplink = 0;
|
1369 |
+
|
1370 |
+
//User does't have permission to download
|
1371 |
+
if ( is_user_logged_in() && count( $matched ) <= 0 && ! @in_array( 'guest', $access ) ) {
|
1372 |
+
$download_url = "#";
|
1373 |
+
$download_link = $download_link_extended = $download_link_popup = Messages::permission_denied( $ID );
|
1374 |
+
if ( get_option( '_wpdm_hide_all', 0 ) == 1 ) {
|
1375 |
+
$download_link = $download_link_extended = $download_link_popup = 'blocked';
|
1376 |
+
}
|
1377 |
+
|
1378 |
+
return $download_link;
|
1379 |
+
}
|
1380 |
+
|
1381 |
+
//Login is required to download
|
1382 |
+
if ( ! @in_array( 'guest', $access ) && ! is_user_logged_in() ) {
|
1383 |
+
|
1384 |
+
$loginform = WPDM()->user->login->form( array( 'redirect' => $_SERVER['REQUEST_URI'] ) );
|
1385 |
+
if ( get_option( '_wpdm_hide_all', 0 ) == 1 ) {
|
1386 |
+
$hide_all_message = get_option( '__wpdm_login_form', 0 ) == 1 ? $loginform : stripcslashes( str_replace( array(
|
1387 |
+
"[loginform]",
|
1388 |
+
"[this_url]",
|
1389 |
+
"[package_url]"
|
1390 |
+
), array( $loginform, $_SERVER['REQUEST_URI'], get_permalink( $ID ) ), $loginmsg ) );
|
1391 |
+
if ( $template_type == 'link' ) {
|
1392 |
+
return "<a href='" . wpdm_login_url( $_SERVER['REQUEST_URI'] ) . "' class='btn btn-danger'>" . __( "Login", "download-manager" ) . "</a>";
|
1393 |
+
} else {
|
1394 |
+
return $hide_all_message;
|
1395 |
+
}
|
1396 |
+
}
|
1397 |
+
$download_url = wpdm_login_url( $_SERVER['REQUEST_URI'] );
|
1398 |
+
$download_link = $download_link_extended = $download_link_popup = stripcslashes( str_replace( array(
|
1399 |
+
"[loginform]",
|
1400 |
+
"[this_url]",
|
1401 |
+
"[package_url]"
|
1402 |
+
), array( $loginform, $_SERVER['REQUEST_URI'], get_permalink( $ID ) ), $loginmsg ) );
|
1403 |
+
|
1404 |
+
return get_option( '__wpdm_login_form', 0 ) == 1 ? $loginform : $download_link;
|
1405 |
+
|
1406 |
+
}
|
1407 |
+
|
1408 |
+
//$package = apply_filters('wpdm_before_apply_locks', $package);
|
1409 |
+
//$package = apply_filters('wpdm_after_prepare_package_data', $package);
|
1410 |
+
|
1411 |
+
$unqid = uniqid();
|
1412 |
+
$stock_limit = (int) get_post_meta( $ID, '__wpdm_quota', true );
|
1413 |
+
$download_count = (int) get_post_meta( $ID, '__wpdm_download_count', true );
|
1414 |
+
if ( $stock_limit > $download_count || $stock_limit == 0 ) {
|
1415 |
+
$lock = 0;
|
1416 |
+
|
1417 |
+
$extras['embed'] = $embed;
|
1418 |
+
$data = self::activeLocks( $ID, $extras );
|
1419 |
+
|
1420 |
+
$terms_lock = (int) get_post_meta( $ID, '__wpdm_terms_lock', true );
|
1421 |
+
$terms_page = (int) get_post_meta( $ID, '__wpdm_terms_page', true );
|
1422 |
+
$terms_title = get_post_meta( $ID, '__wpdm_terms_title', true );
|
1423 |
+
$terms_conditions = get_post_meta( $ID, '__wpdm_terms_conditions', true );
|
1424 |
+
if ( $terms_page ) {
|
1425 |
+
$terms_page = get_post( $terms_page );
|
1426 |
+
$terms_title = $terms_page->post_title;
|
1427 |
+
$terms_conditions = $terms_page->post_content;
|
1428 |
+
}
|
1429 |
+
$terms_check_label = get_post_meta( $ID, '__wpdm_terms_check_label', true );
|
1430 |
+
if ( $terms_lock !== 0 && ( ! function_exists( 'wpdmpp_effective_price' ) || wpdmpp_effective_price( $ID ) == 0 ) ) {
|
1431 |
+
if ( ! self::isLocked( $ID ) && ! $embed ) {
|
1432 |
+
$data = "<a href='#unlock' class='wpdm-download-link wpdm-download-locked {$style}' data-package='{$ID}'>{$link_label}</a>";
|
1433 |
+
} else {
|
1434 |
+
$data = $data ? $data : $download_link;
|
1435 |
+
}
|
1436 |
+
if ( $embed == 1 ) {
|
1437 |
+
$data = "<div class='panel panel-default card terms-panel' style='margin: 0 0 10px 0'><div class='panel-heading card-header'>{$terms_title}</div><div class='panel-body card-body' style='max-height: 200px;overflow: auto'>{$terms_conditions}</div><div class='panel-footer card-footer'><label><input data-pid='{$ID}' class='wpdm-checkbox terms_checkbox terms_checkbox_{$ID}' type='checkbox'> {$terms_check_label}</label></div><div class='panel-footer card-footer bg-white download_footer_{$ID}' style='display:none;'>{$data}</div></div><script>jQuery(function($){ $('#wpdm-filelist-{$ID} .btn.inddl, #xfilelist .btn.inddl').attr('disabled', 'disabled'); });</script>";
|
1438 |
+
}
|
1439 |
+
|
1440 |
+
}
|
1441 |
+
|
1442 |
+
if ( $data != "" ) {
|
1443 |
+
$data = apply_filters( 'wpdm_download_link', $data, $extras + array( 'ID' => $ID, 'id' => $ID ) );
|
1444 |
+
|
1445 |
+
return $data;
|
1446 |
+
}
|
1447 |
+
|
1448 |
+
|
1449 |
+
$data = $download_link;
|
1450 |
+
|
1451 |
+
|
1452 |
+
} else {
|
1453 |
+
$data = "<button class='btn btn-danger btn-block' type='button' disabled='disabled' data-title='DOWNLOAD ERROR:'>" . __( "Limit Over!", "download-manager" ) . "</button>";
|
1454 |
+
}
|
1455 |
+
if ( $data == 'loginform' ) {
|
1456 |
+
return WPDM()->user->login->form();
|
1457 |
+
}
|
1458 |
+
$data = apply_filters( 'wpdm_download_link', $data, $extras + array( 'ID' => $ID, 'id' => $ID ) );
|
1459 |
+
|
1460 |
+
return $data;
|
1461 |
+
|
1462 |
+
}
|
1463 |
+
|
1464 |
+
/**
|
1465 |
+
* @usage Generate download url for public/open downloads, the url will not work for the packages with lock option
|
1466 |
+
*
|
1467 |
+
* @param $ID
|
1468 |
+
* @param $ext
|
1469 |
+
*
|
1470 |
+
* @return string
|
1471 |
+
*/
|
1472 |
+
public function getDownloadURL( $ID, $ext = array() ) {
|
1473 |
+
if ( self::isLocked( $ID ) && ! Session::get( '__wpdm_unlocked_' . $ID ) ) {
|
1474 |
+
return '#locked';
|
1475 |
+
}
|
1476 |
+
if ( ! is_array( $ext ) ) {
|
1477 |
+
$ext = [];
|
1478 |
+
}
|
1479 |
+
$ext['wpdmdl'] = $ID;
|
1480 |
+
$ext['refresh'] = uniqid() . time();
|
1481 |
+
$permalink = get_permalink( $ID );
|
1482 |
+
$permalink = apply_filters( "wpdm_download_url_base", $permalink, $ID );
|
1483 |
+
$download_url = add_query_arg( $ext, $permalink );
|
1484 |
+
$flat = (int) get_option( '__wpdm_flat_download_url', 0 );
|
1485 |
+
$code = json_encode( $ext );
|
1486 |
+
$code = base64_encode( $code );
|
1487 |
+
$code = rtrim( $code, '=' );
|
1488 |
+
$filename = isset( $ext['filename'] ) ? $ext['filename'] : '';
|
1489 |
+
if ( isset( $ext['ind'] ) && $filename == '' ) {
|
1490 |
+
$files = $this->getFiles( $ID );
|
1491 |
+
$filename = wpdm_basename( $files[ $ext['ind'] ] );
|
1492 |
+
}
|
1493 |
+
if ( ! isset( $ext['ind'] ) && $filename == '' ) {
|
1494 |
+
$files = $this->getFiles( $ID );
|
1495 |
+
if ( count( $files ) > 1 ) {
|
1496 |
+
$filename = sanitize_file_name( get_the_title( $ID ) ) . ".zip";
|
1497 |
+
} else {
|
1498 |
+
$filename = array_shift( $files );
|
1499 |
+
$filename = wpdm_basename( $filename );
|
1500 |
+
}
|
1501 |
+
|
1502 |
+
}
|
1503 |
+
if ( $flat ) {
|
1504 |
+
$download_url = home_url( "/wpdmdl/{$ID}-{$code}/{$filename}" );
|
1505 |
+
}
|
1506 |
+
|
1507 |
+
return $download_url;
|
1508 |
+
}
|
1509 |
+
|
1510 |
+
/**
|
1511 |
+
* @param $ID
|
1512 |
+
*
|
1513 |
+
* @return false|string
|
1514 |
+
*/
|
1515 |
+
public function getMasterDownloadURL( $ID ) {
|
1516 |
+
$package_url = get_permalink( $ID );
|
1517 |
+
$params['wpdmdl'] = $ID;
|
1518 |
+
$params['masterkey'] = get_post_meta( $ID, '__wpdm_masterkey', true );
|
1519 |
+
$download_url = add_query_arg( $params, $package_url );
|
1520 |
+
|
1521 |
+
return $download_url;
|
1522 |
+
}
|
1523 |
+
|
1524 |
+
/**
|
1525 |
+
* @param $ID
|
1526 |
+
* @param $Key
|
1527 |
+
*
|
1528 |
+
* @return bool
|
1529 |
+
*/
|
1530 |
+
public function validateMasterKey( $ID, $Key ) {
|
1531 |
+
if ( $Key === '' ) {
|
1532 |
+
return false;
|
1533 |
+
}
|
1534 |
+
$masterKey = get_post_meta( $ID, '__wpdm_masterkey', true );
|
1535 |
+
if ( $masterKey === '' ) {
|
1536 |
+
return false;
|
1537 |
+
}
|
1538 |
+
if ( $masterKey === $Key ) {
|
1539 |
+
return true;
|
1540 |
+
}
|
1541 |
+
|
1542 |
+
return false;
|
1543 |
+
}
|
1544 |
+
|
1545 |
+
/**
|
1546 |
+
* @param $ID
|
1547 |
+
* @param int $usageLimit
|
1548 |
+
* @param int $expirePeriod seconds
|
1549 |
+
*
|
1550 |
+
* @return string
|
1551 |
+
*/
|
1552 |
+
function expirableDownloadLink( $ID, $usageLimit = 10, $expirePeriod = 999999, $sessionOnly = true ) {
|
1553 |
+
$key = uniqid();
|
1554 |
+
$exp = array( 'use' => $usageLimit, 'expire' => time() + $expirePeriod );
|
1555 |
+
if ( ! $sessionOnly ) {
|
1556 |
+
update_post_meta( $ID, "__wpdmkey_" . $key, $exp );
|
1557 |
+
} else {
|
1558 |
+
TempStorage::set( "__wpdmkey_{$key}", $exp, time() + $expirePeriod );
|
1559 |
+
}
|
1560 |
+
//Session::set( '__wpdm_unlocked_'.$ID , 1 );
|
1561 |
+
//$download_url = $this->getDownloadURL($ID, "_wpdmkey={$key}");
|
1562 |
+
$permalink = get_permalink( $ID );
|
1563 |
+
$permalink = apply_filters( "wpdm_download_url_base", $permalink, $ID );
|
1564 |
+
$download_url = add_query_arg( array( "wpdmdl" => $ID, "_wpdmkey" => $key ), $permalink );
|
1565 |
+
|
1566 |
+
return $download_url;
|
1567 |
+
}
|
1568 |
+
|
1569 |
+
/**
|
1570 |
+
* @param $ID
|
1571 |
+
* @param int $usageLimit
|
1572 |
+
* @param int $expirePeriod seconds
|
1573 |
+
*
|
1574 |
+
* @return string
|
1575 |
+
*/
|
1576 |
+
static function expirableDownloadPage( $ID, $usageLimit = 10, $expirePeriod = 604800, $sessionOnly = true ) {
|
1577 |
+
$key = uniqid();
|
1578 |
+
$exp = array( 'use' => $usageLimit, 'expire' => time() + $expirePeriod );
|
1579 |
+
if ( ! $sessionOnly ) {
|
1580 |
+
update_post_meta( $ID, "__wpdmkey_" . $key, $exp );
|
1581 |
+
} else {
|
1582 |
+
TempStorage::set( "__wpdmkey_{$key}", $exp, time() + $expirePeriod );
|
1583 |
+
}
|
1584 |
+
$download_page_key = Crypt::encrypt( array( 'pid' => $ID, 'key' => $key ) );
|
1585 |
+
$download_page = home_url( "wpdm-download/{$download_page_key}" );
|
1586 |
+
|
1587 |
+
return $download_page;
|
1588 |
+
}
|
1589 |
+
|
1590 |
+
|
1591 |
+
/**
|
1592 |
+
* @usage Fetch link/page template and return generated html
|
1593 |
+
*
|
1594 |
+
* @param $template
|
1595 |
+
* @param $vars
|
1596 |
+
* @param string $type
|
1597 |
+
*
|
1598 |
+
* @return mixed|string
|
1599 |
+
*/
|
1600 |
+
public function fetchTemplate( $template, $vars, $type = 'link' ) {
|
1601 |
+
if ( ! is_array( $vars ) && is_int( $vars ) && $vars > 0 ) {
|
1602 |
+
$vars = array( 'ID' => $vars );
|
1603 |
+
}
|
1604 |
+
if ( ! isset( $vars['ID'] ) || intval( $vars['ID'] ) < 1 ) {
|
1605 |
+
return '';
|
1606 |
+
}
|
1607 |
+
|
1608 |
+
$loginmsg = Messages::login_required( $vars['ID'] );
|
1609 |
+
|
1610 |
+
if ( ! is_user_logged_in() && count( self::allowedRoles( $vars['ID'] ) ) >= 0 && ! self::userCanAccess( $vars['ID'] ) ) {
|
1611 |
+
$loginform = wpdm_login_form( array( 'redirect' => get_permalink( $vars['ID'] ) ) );
|
1612 |
+
$hide_all_message = get_option( '__wpdm_login_form', 0 ) == 1 ? $loginform : stripcslashes( str_replace( array(
|
1613 |
+
"[loginform]",
|
1614 |
+
"[this_url]",
|
1615 |
+
"[package_url]"
|
1616 |
+
), array( $loginform, $_SERVER['REQUEST_URI'], get_permalink( $vars['ID'] ) ), $loginmsg ) );
|
1617 |
+
if ( get_option( '_wpdm_hide_all', 0 ) == 1 ) {
|
1618 |
+
return $type == 'page' ? $hide_all_message : '';
|
1619 |
+
}
|
1620 |
+
}
|
1621 |
+
|
1622 |
+
if ( is_user_logged_in() && ! self::userCanAccess( $vars['ID'] ) && get_option( '_wpdm_hide_all', 0 ) == 1 ) {
|
1623 |
+
return $type != 'page' ? "" : get_option( '__wpdm_permission_denied_msg', __( "You are not allowed to download this item!", "download-manager" ) );
|
1624 |
+
}
|
1625 |
+
|
1626 |
+
|
1627 |
+
/*$default['link'] = 'link-template-default.php';
|
1628 |
$default['page'] = 'page-template-default.php';
|
1629 |
|
1630 |
|
1677 |
|
1678 |
}*/
|
1679 |
|
1680 |
+
$ret = $this->prepare( $vars['ID'], $template, $type );
|
1681 |
+
if ( ! is_wp_error( $ret ) ) {
|
1682 |
+
$vars = $this->packageData;
|
1683 |
+
} else {
|
1684 |
+
return '';
|
1685 |
+
}
|
1686 |
+
|
1687 |
+
// Get template content
|
1688 |
+
$template = $this->getTemplateContent( $template, $vars['ID'], $type );
|
1689 |
+
|
1690 |
+
if ( isset( $vars['__loginform_only'] ) && $vars['__loginform_only'] != '' ) {
|
1691 |
+
return $vars['__loginform_only'];
|
1692 |
+
}
|
1693 |
+
|
1694 |
+
preg_match_all( "/\[cf ([^\]]+)\]/", $template, $cfmatches );
|
1695 |
+
preg_match_all( "/\[thumb_([0-9]+)x([0-9]+)\]/", $template, $matches );
|
1696 |
+
preg_match_all( "/\[thumb_url_([0-9]+)x([0-9]+)\]/", $template, $umatches );
|
1697 |
+
preg_match_all( "/\[thumb_gallery_([0-9]+)x([0-9]+)\]/", $template, $gmatches );
|
1698 |
+
preg_match_all( "/\[excerpt_([0-9]+)\]/", $template, $xmatches );
|
1699 |
+
preg_match_all( "/\[pdf_thumb_([0-9]+)x([0-9]+)\]/", $template, $pmatches );
|
1700 |
+
preg_match_all( "/\[txt=([^\]]+)\]/", $template, $txtmatches );
|
1701 |
+
preg_match_all( "/\[hide_empty:([^\]]+)\]/", $template, $hematches );
|
1702 |
+
preg_match_all( "/\[video_player_([0-9]+)\]/", $template, $vdmatches );
|
1703 |
+
preg_match_all( "/\[product_preview_([0-9]+)x([0-9]+)\]/", $template, $ppmatches );
|
1704 |
+
preg_match_all( "/\[file_list_extended_([0-9]+)x([0-9]+)x([0-9]+)\]/", $template, $flematches );
|
1705 |
+
preg_match_all( "/\[image_gallery_([0-9]+)x([0-9]+)x([0-9]+)\]/", $template, $igematches );
|
1706 |
+
|
1707 |
+
|
1708 |
+
//$thumb = wp_get_attachment_image_src(get_post_thumbnail_id($vars['ID']), 'full');
|
1709 |
+
//$vars['preview'] = $thumb['0'];
|
1710 |
+
//$vars['featured_image'] = ($vars['preview'] != '')?"<img src='{$vars['preview']}' alt='{$vars['title']}' />":"";
|
1711 |
+
|
1712 |
+
$tfiles = $vars['files'];
|
1713 |
+
$pdf = is_array( $tfiles ) ? array_shift( $tfiles ) : "";
|
1714 |
+
$ext = FileSystem::fileExt( $pdf );
|
1715 |
+
|
1716 |
+
// [video_player_...]
|
1717 |
+
foreach ( $vdmatches[0] as $nd => $scode ) {
|
1718 |
+
$scode = str_replace( array( '[', ']' ), '', $scode );
|
1719 |
+
$vars[ $scode ] = self::videoPlayer( $vars['ID'], $vars['files'], $vdmatches[1][ $nd ] );
|
1720 |
+
}
|
1721 |
+
|
1722 |
+
//Replace all file list extended tags
|
1723 |
+
foreach ( $flematches[0] as $nd => $scode ) {
|
1724 |
+
$scode = str_replace( array( "[", "]" ), "", $scode );
|
1725 |
+
$vars[ $scode ] = FileList::Box( $vars, $flematches[1][ $nd ], $flematches[2][ $nd ], $flematches[3][ $nd ] );
|
1726 |
+
}
|
1727 |
+
|
1728 |
+
//Replace all image gallery tags
|
1729 |
+
foreach ( $igematches[0] as $nd => $scode ) {
|
1730 |
+
$scode = str_replace( array( "[", "]" ), "", $scode );
|
1731 |
+
$vars[ $scode ] = FileList::imageGallery( $vars, $igematches[1][ $nd ], $igematches[2][ $nd ], $igematches[3][ $nd ] );
|
1732 |
+
}
|
1733 |
+
|
1734 |
+
|
1735 |
+
//Replace all txt variables
|
1736 |
+
foreach ( $txtmatches[0] as $nd => $scode ) {
|
1737 |
+
$scode = str_replace( array( '[', ']' ), '', $scode );
|
1738 |
+
$vars[ $scode ] = __( $txtmatches[1][ $nd ], "download-manager" );
|
1739 |
+
}
|
1740 |
+
|
1741 |
+
// Parse [pdf_thumb] tag in link/page template
|
1742 |
+
if ( strpos( $template, 'pdf_thumb' ) ) {
|
1743 |
+
if ( $ext == 'pdf' ) {
|
1744 |
+
$pdf_preview = FileSystem::pdfThumbnail( $pdf, $vars['ID'] );
|
1745 |
+
$vars['pdf_thumb'] = "<img alt='{$vars['title']}' src='" . $pdf_preview . "' />";
|
1746 |
+
$vars['pdf_thumb_url'] = $pdf_preview;
|
1747 |
+
$vars['pdf_name'] = str_replace( [ "pdf", "PDF" ], "", wp_basename( $pdf ) );
|
1748 |
+
} else {
|
1749 |
+
$vars['pdf_thumb'] = $vars['preview'] != '' ? "<img alt='{$vars['title']}' src='{$vars['preview']}' />" : "";
|
1750 |
+
}
|
1751 |
+
}
|
1752 |
+
|
1753 |
+
// Parse [pdf_thumb_WxH] tag in link/page template
|
1754 |
+
foreach ( $pmatches[0] as $nd => $scode ) {
|
1755 |
+
$imsrc = wpdm_dynamic_thumb( FileSystem::pdfThumbnail( $pdf, $vars['ID'] ), array(
|
1756 |
+
$pmatches[1][ $nd ],
|
1757 |
+
$pmatches[2][ $nd ]
|
1758 |
+
) );
|
1759 |
+
$scode = str_replace( array( "[", "]" ), "", $scode );
|
1760 |
+
$vars[ $scode ] = $imsrc != '' ? "<img src='" . $imsrc . "' alt='{$vars['title']}' />" : '';
|
1761 |
+
}
|
1762 |
+
|
1763 |
+
// Parse [file_type] tag in link/page template
|
1764 |
+
if ( strpos( $template, 'file_type' ) ) {
|
1765 |
+
$vars['file_types'] = self::fileTypes( $vars['ID'], false );
|
1766 |
+
if ( is_array( $vars['file_types'] ) ) {
|
1767 |
+
$vars['file_types'] = implode( ", ", $vars['file_types'] );
|
1768 |
+
}
|
1769 |
+
$vars['file_type_icons'] = self::fileTypes( $vars['ID'] );
|
1770 |
+
}
|
1771 |
+
|
1772 |
+
$crop = get_option( '__wpdm_crop_thumbs', true );
|
1773 |
+
|
1774 |
+
// [thumb_WxH]
|
1775 |
+
foreach ( $matches[0] as $nd => $scode ) {
|
1776 |
+
$imsrc = wpdm_dynamic_thumb( $vars['preview'], array(
|
1777 |
+
$matches[1][ $nd ],
|
1778 |
+
$matches[2][ $nd ]
|
1779 |
+
), $crop );
|
1780 |
+
$scode = str_replace( array( "[", "]" ), "", $scode );
|
1781 |
+
$vars[ $scode ] = $vars['preview'] != '' ? "<img class='wpdm-thumb wpdm-thumb-{$matches[1][$nd]}x{$matches[2][$nd]} wpdm-thumb-{$vars['ID']}' src='" . $imsrc . "' alt='{$vars['title']}' />" : '';
|
1782 |
+
}
|
1783 |
+
|
1784 |
+
// [thumb_url...]
|
1785 |
+
foreach ( $umatches[0] as $nd => $scode ) {
|
1786 |
+
$scode = str_replace( array( "[", "]" ), "", $scode );
|
1787 |
+
$vars[ $scode ] = $vars['preview'] != '' ? wpdm_dynamic_thumb( $vars['preview'], array(
|
1788 |
+
$umatches[1][ $nd ],
|
1789 |
+
$umatches[2][ $nd ]
|
1790 |
+
), $crop ) : '';
|
1791 |
+
}
|
1792 |
+
|
1793 |
+
// [thumb_gallery...]
|
1794 |
+
foreach ( $gmatches[0] as $nd => $scode ) {
|
1795 |
+
$scode = str_replace( array( "[", "]" ), "", $scode );
|
1796 |
+
$vars[ $scode ] = $this->additionalPreviewImages( $vars, $gmatches[1][ $nd ], $gmatches[2][ $nd ] );
|
1797 |
+
}
|
1798 |
+
|
1799 |
+
// [product_preview...]
|
1800 |
+
foreach ( $ppmatches[0] as $nd => $scode ) {
|
1801 |
+
$scode = str_replace( array( "[", "]" ), "", $scode );
|
1802 |
+
$vars[ $scode ] = self::productPreview( $vars['ID'], $vars['files'], $ppmatches[1][ $nd ], $ppmatches[2][ $nd ] );
|
1803 |
+
}
|
1804 |
+
|
1805 |
+
// [excerpt_...]
|
1806 |
+
foreach ( $xmatches[0] as $nd => $scode ) {
|
1807 |
+
$ss = substr( strip_tags( $vars['description'] ), 0, intval( $xmatches[1][ $nd ] ) );
|
1808 |
+
$tmp = explode( " ", substr( strip_tags( $vars['description'] ), intval( $xmatches[1][ $nd ] ) ) );
|
1809 |
+
$bw = array_shift( $tmp );
|
1810 |
+
$ss .= $bw;
|
1811 |
+
$scode = str_replace( array( "[", "]" ), "", $scode );
|
1812 |
+
$vars[ $scode ] = $ss . '...';
|
1813 |
+
}
|
1814 |
+
|
1815 |
+
if ( $type == 'page' && ( strpos( $template, '[similar_downloads]' ) || strpos( $vars['description'], '[similar_downloads]' ) ) ) {
|
1816 |
+
$vars['similar_downloads'] = $this->similarPackages( $vars, 6 );
|
1817 |
+
}
|
1818 |
+
|
1819 |
+
if ( strpos( $template, 'doc_preview' ) ) {
|
1820 |
+
$vars['doc_preview'] = self::docPreview( $vars );
|
1821 |
+
}
|
1822 |
+
|
1823 |
+
if ( substr_count( $template, 'video_preview_modal' ) ) {
|
1824 |
+
$vars['video_preview_modal'] = self::videoPreviewModal( $vars, $type );
|
1825 |
+
}
|
1826 |
+
|
1827 |
+
|
1828 |
+
$vars['fav_button'] = self::favBtn( $vars['ID'] );
|
1829 |
+
$vars['fav_button_sm'] = self::favBtn( $vars['ID'], array(
|
1830 |
+
'size' => 'btn-sm',
|
1831 |
+
'a2f_label' => "<i class='fa fa-heart'></i> " . __( "Add to favourite", "download-manager" ),
|
1832 |
+
'rff_label' => "<i class='fa fa-heart'></i> " . __( "Remove from favourite", "download-manager" )
|
1833 |
+
) );
|
1834 |
+
$vars['fav_button_ico_sm'] = self::favBtn( $vars['ID'], array(
|
1835 |
+
'size' => 'btn-sm',
|
1836 |
+
'a2f_label' => "<i class='far fa-heart'></i>",
|
1837 |
+
'rff_label' => "<i class='fas fa-heart'></i>"
|
1838 |
+
) );
|
1839 |
+
$vars['fav_button_ico'] = self::favBtn( $vars['ID'], array(
|
1840 |
+
'size' => '',
|
1841 |
+
'a2f_label' => "<i class='fa fa-heart'></i>",
|
1842 |
+
'rff_label' => "<i class='fa fa-heart'></i>"
|
1843 |
+
) );
|
1844 |
+
|
1845 |
+
|
1846 |
+
// If need to re-process any data before fetch template
|
1847 |
+
$vars['__template_type'] = $type;
|
1848 |
+
$vars = apply_filters( "wdm_before_fetch_template", $vars, $template, $type );
|
1849 |
+
|
1850 |
+
foreach ( $hematches[0] as $index => $hide_empty ) {
|
1851 |
+
$hide_empty = str_replace( array( '[', ']' ), '', $hide_empty );
|
1852 |
+
if ( ! isset( $vars[ $hematches[1][ $index ] ] ) || ( $vars[ $hematches[1][ $index ] ] == '' || $vars[ $hematches[1][ $index ] ] == '0' ) ) {
|
1853 |
+
$vars[ $hide_empty ] = 'wpdm_hide wpdm_remove_empty';
|
1854 |
+
} else {
|
1855 |
+
$value[ $hide_empty ] = '';
|
1856 |
+
}
|
1857 |
+
}
|
1858 |
+
|
1859 |
+
|
1860 |
+
$keys = array();
|
1861 |
+
$values = array();
|
1862 |
+
|
1863 |
+
foreach ( $vars as $key => $value ) {
|
1864 |
+
if ( ! is_array( $value ) && ! is_object( $value ) ) {
|
1865 |
+
$keys[] = "[$key]";
|
1866 |
+
$values[] = $value;
|
1867 |
+
}
|
1868 |
+
}
|
1869 |
+
|
1870 |
+
|
1871 |
+
$loginform = wpdm_login_form( array( 'redirect' => get_permalink( $vars['ID'] ) ) );
|
1872 |
+
$hide_all_message = get_option( '__wpdm_login_form', 0 ) == 1 ? $loginform : stripcslashes( str_replace( array(
|
1873 |
+
"[loginform]",
|
1874 |
+
"[this_url]",
|
1875 |
+
"[package_url]"
|
1876 |
+
), array( $loginform, $_SERVER['REQUEST_URI'], get_permalink( $vars['ID'] ) ), $loginmsg ) );
|
1877 |
+
|
1878 |
+
if ( $vars['download_link'] == 'blocked' && $type == 'link' ) {
|
1879 |
+
return "";
|
1880 |
+
}
|
1881 |
+
if ( $vars['download_link'] == 'blocked' && $type == 'page' ) {
|
1882 |
+
return get_option( '__wpdm_permission_denied_msg' );
|
1883 |
+
}
|
1884 |
+
if ( $vars['download_link'] == 'loginform' && $type == 'link' ) {
|
1885 |
+
return "";
|
1886 |
+
}
|
1887 |
+
if ( $vars['download_link'] == 'loginform' && $type == 'page' ) {
|
1888 |
+
return $hide_all_message;
|
1889 |
+
}
|
1890 |
+
|
1891 |
+
|
1892 |
+
$template = str_replace( $keys, $values, @stripcslashes( $template ) );
|
1893 |
+
|
1894 |
+
$template = apply_filters( "wpdm_after_fetch_template", $template, $vars );
|
1895 |
+
|
1896 |
+
//wp_reset_query();
|
1897 |
+
//wp_reset_postdata();
|
1898 |
+
return $template;
|
1899 |
+
}
|
1900 |
+
|
1901 |
+
/*public static function parseTemplate($template, $post, $type = 'link')
|
1902 |
{
|
1903 |
|
1904 |
if (!strpos(strip_tags($template), "]")) {
|
1943 |
return $template;
|
1944 |
}*/
|
1945 |
|
1946 |
+
/**
|
1947 |
+
* @usage Find attached files types with a package
|
1948 |
+
*
|
1949 |
+
* @param $ID
|
1950 |
+
* @param bool|true $img
|
1951 |
+
*
|
1952 |
+
* @return array|string
|
1953 |
+
*/
|
1954 |
+
public static function fileTypes( $ID, $img = true, $size = 16 ) {
|
1955 |
+
$files = maybe_unserialize( get_post_meta( $ID, '__wpdm_files', true ) );
|
1956 |
+
$ext = array();
|
1957 |
+
if ( is_array( $files ) ) {
|
1958 |
+
foreach ( $files as $f ) {
|
1959 |
+
$f = trim( $f );
|
1960 |
+
$ext[] = FileSystem::fileExt( $f );
|
1961 |
+
}
|
1962 |
+
}
|
1963 |
+
|
1964 |
+
$ext = array_unique( $ext );
|
1965 |
+
$exico = '';
|
1966 |
+
foreach ( $ext as $exi ) {
|
1967 |
+
$exico .= "<img alt='{$exi}' title='{$exi}' class='ttip' style='width:{$size}px;height:{$size}px;' src='" . FileSystem::fileTypeIcon( $exi ) . "' /> ";
|
1968 |
+
}
|
1969 |
+
if ( $img ) {
|
1970 |
+
return $exico;
|
1971 |
+
}
|
1972 |
+
|
1973 |
+
return $ext;
|
1974 |
+
}
|
1975 |
+
|
1976 |
+
|
1977 |
+
/**
|
1978 |
+
* @param $package
|
1979 |
+
*
|
1980 |
+
* @return string
|
1981 |
+
* @usage Generate Google Doc Preview
|
1982 |
+
*/
|
1983 |
+
public function docPreview( $package ) {
|
1984 |
+
|
1985 |
+
//$files = $package['files'];
|
1986 |
+
$files = $this->getFiles( $package['ID'] );
|
1987 |
+
if ( ! is_array( $files ) ) {
|
1988 |
+
return "";
|
1989 |
+
}
|
1990 |
+
$ind = - 1;
|
1991 |
+
$fext = '';
|
1992 |
+
foreach ( $files as $i => $sfile ) {
|
1993 |
+
$ifile = $sfile;
|
1994 |
+
$sfile = explode( ".", $sfile );
|
1995 |
+
$fext = end( $sfile );
|
1996 |
+
if ( in_array( end( $sfile ), array( 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx' ) ) ) {
|
1997 |
+
$ind = $i;
|
1998 |
+
break;
|
1999 |
+
}
|
2000 |
+
}
|
2001 |
+
|
2002 |
+
if ( $ind == - 1 ) {
|
2003 |
+
return "";
|
2004 |
+
}
|
2005 |
+
$ext = count( $files ) > 1 ? 'ind=' . $ind : '';
|
2006 |
+
$params = array( 'ind' => $ind, 'filename' => $files[ $ind ] );
|
2007 |
+
$url = $this->getDownloadURL( $package['ID'], $params );
|
2008 |
+
$url .= "&open=1";
|
2009 |
+
if ( strpos( $ifile, "://" ) ) {
|
2010 |
+
$url = $ifile;
|
2011 |
+
}
|
2012 |
+
$doc_preview_html = FileSystem::docViewer( $url, $package['ID'], $fext );
|
2013 |
+
$doc_preview_html = apply_filters( 'wpdm_doc_preview', $doc_preview_html, $package, $url, $fext );
|
2014 |
+
|
2015 |
+
return $doc_preview_html;
|
2016 |
+
}
|
2017 |
+
|
2018 |
+
/**
|
2019 |
+
* Get additional preview images
|
2020 |
+
*
|
2021 |
+
* @param $file
|
2022 |
+
* @param $w
|
2023 |
+
* @param $h
|
2024 |
+
*
|
2025 |
+
* @return string
|
2026 |
+
*/
|
2027 |
+
function additionalPreviewImages( $file, $w, $h ) {
|
2028 |
+
|
2029 |
+
$file['additional_previews'] = maybe_unserialize( get_post_meta( $file['ID'], '__wpdm_additional_previews', true ) );
|
2030 |
+
$k = 0;
|
2031 |
+
$img = '';
|
2032 |
+
$id = uniqid();
|
2033 |
+
if ( $file['additional_previews'] ) {
|
2034 |
+
foreach ( $file['additional_previews'] as $p ) {
|
2035 |
+
++ $k;
|
2036 |
+
if ( is_numeric( $p ) ) {
|
2037 |
+
$img .= "<a href='" . wp_get_attachment_url( $p ) . "' id='more_previews_a_{$k}' class='more_previews_a imgpreview wpdm-lightbox' data-lightbox-gallery='gallery_{$id}' rel='previews'><img id='more_previews_{$k}' class='more_previews img-rounded' src='" . wpdm_dynamic_thumb( get_attached_file( $p ), array(
|
2038 |
+
$w,
|
2039 |
+
$h
|
2040 |
+
) ) . "'/></a>";
|
2041 |
+
} else {
|
2042 |
+
$img .= "<a href='{$p}' id='more_previews_a_{$k}' class='more_previews_a imgpreview wpdm-lightbox' data-lightbox-gallery='gallery_{$id}' rel='previews' ><img id='more_previews_{$k}' class='more_previews img-rounded' src='" . wpdm_dynamic_thumb( $p, array(
|
2043 |
+
$w,
|
2044 |
+
$h
|
2045 |
+
) ) . "'/></a>";
|
2046 |
+
}
|
2047 |
+
}
|
2048 |
+
}
|
2049 |
+
$js = ""; // "<script>jQuery(function($){ $('a.more_previews_a').nivoLightbox(); });</script>";
|
2050 |
+
|
2051 |
+
return $img . $js;
|
2052 |
+
}
|
2053 |
+
|
2054 |
+
/**
|
2055 |
+
* @usage Generates view preview modal link of the given package
|
2056 |
+
*
|
2057 |
+
* @param $package
|
2058 |
+
* @param int $embed
|
2059 |
+
* @param array $extras
|
2060 |
+
*
|
2061 |
+
* @return string
|
2062 |
+
*/
|
2063 |
+
public function videoPreviewModal( $package, $template_type = 'link' ) {
|
2064 |
+
if ( is_int( $package ) ) {
|
2065 |
+
$package = get_post( $package, ARRAY_A );
|
2066 |
+
}
|
2067 |
+
$link_label = wpdm_valueof( $package, 'link_label' );
|
2068 |
+
$link_label = $link_label ? $link_label : $this->linkLabel( $package['ID'] );
|
2069 |
+
$style = wpdm_download_button_style( $template_type === 'page', $package['ID'] );
|
2070 |
+
$files = isset( $package['files'] ) ? $package['files'] : $this->getFiles( $package['ID'] );
|
2071 |
+
$video = "";
|
2072 |
+
foreach ( $files as $file ) {
|
2073 |
+
if ( substr_count( $file, 'youtu.be' ) || substr_count( $file, 'youtube.com' ) || substr_count( $file, 'vimeo.com' ) ) {
|
2074 |
+
$video = $file;
|
2075 |
+
}
|
2076 |
+
}
|
2077 |
+
$link = "<a class='wpdm-lightbox {$style}' href='{$video}'>{$link_label}</a>";
|
2078 |
+
|
2079 |
+
return $link;
|
2080 |
+
|
2081 |
+
}
|
2082 |
+
|
2083 |
+
/**
|
2084 |
+
* Get package link label
|
2085 |
+
*
|
2086 |
+
* @param $ID
|
2087 |
+
*
|
2088 |
+
* @return mixed|string|void
|
2089 |
+
*/
|
2090 |
+
public function linkLabel( $ID ) {
|
2091 |
+
$link_label = get_post_meta( $ID, '__wpdm_link_label', true );
|
2092 |
+
$link_label = esc_attr( $link_label );
|
2093 |
+
$link_label = $link_label ? $link_label : __( "Download", "download-manager" );
|
2094 |
+
|
2095 |
+
return $link_label;
|
2096 |
+
}
|
2097 |
+
|
2098 |
+
/**
|
2099 |
+
* @usage Create New Package
|
2100 |
+
*
|
2101 |
+
* @param $data
|
2102 |
+
*
|
2103 |
+
* @return mixed
|
2104 |
+
*/
|
2105 |
+
public static function create( $package_data ) {
|
2106 |
+
|
2107 |
+
if ( isset( $package_data['post_type'] ) ) {
|
2108 |
+
unset( $package_data['post_type'] );
|
2109 |
+
}
|
2110 |
+
|
2111 |
+
$package_data_core = array(
|
2112 |
+
'post_title' => '',
|
2113 |
+
'post_content' => '',
|
2114 |
+
'post_excerpt' => '',
|
2115 |
+
'post_status' => 'publish',
|
2116 |
+
'post_type' => 'wpdmpro',
|
2117 |
+
'post_author' => get_current_user_id(),
|
2118 |
+
'ping_status' => get_option( 'default_ping_status' ),
|
2119 |
+
'post_parent' => 0,
|
2120 |
+
'menu_order' => 0,
|
2121 |
+
'to_ping' => '',
|
2122 |
+
'pinged' => '',
|
2123 |
+
'post_password' => '',
|
2124 |
+
'guid' => '',
|
2125 |
+
'post_content_filtered' => '',
|
2126 |
+
'import_id' => 0
|
2127 |
+
);
|
2128 |
+
|
2129 |
+
$package_data_meta = array(
|
2130 |
+
'files' => array(),
|
2131 |
+
'fileinfo' => array(),
|
2132 |
+
'package_dir' => '',
|
2133 |
+
'link_label' => __( "Download", "download-manager" ),
|
2134 |
+
'download_count' => 0,
|
2135 |
+
'view_count' => 0,
|
2136 |
+
'version' => '1.0.0',
|
2137 |
+
'stock' => 0,
|
2138 |
+
'package_size' => 0,
|
2139 |
+
'package_size_b' => 0,
|
2140 |
+
'access' => '',
|
2141 |
+
'individual_file_download' => - 1,
|
2142 |
+
'cache_zip' => - 1,
|
2143 |
+
'template' => 'link-template-panel.php',
|
2144 |
+
'page_template' => 'page-template-1col-flat.php',
|
2145 |
+
'password_lock' => '0',
|
2146 |
+
'facebook_lock' => '0',
|
2147 |
+
'gplusone_lock' => '0',
|
2148 |
+
'linkedin_lock' => '0',
|
2149 |
+
'tweet_lock' => '0',
|
2150 |
+
'email_lock' => '0',
|
2151 |
+
'icon' => '',
|
2152 |
+
'import_id' => 0
|
2153 |
+
);
|
2154 |
+
|
2155 |
+
foreach ( $package_data_core as $key => &$value ) {
|
2156 |
+
$value = isset( $package_data[ $key ] ) ? $package_data[ $key ] : $package_data_core[ $key ];
|
2157 |
+
}
|
2158 |
+
|
2159 |
+
if ( ! isset( $package_data['ID'] ) ) {
|
2160 |
+
$post_id = wp_insert_post( $package_data_core );
|
2161 |
+
} else {
|
2162 |
+
$post_id = $package_data['ID'];
|
2163 |
+
$package_data_core['ID'] = $post_id;
|
2164 |
+
wp_update_post( $package_data_core );
|
2165 |
+
}
|
2166 |
+
|
2167 |
+
foreach ( $package_data_meta as $key => $value ) {
|
2168 |
+
$value = isset( $package_data[ $key ] ) ? $package_data[ $key ] : $package_data_meta[ $key ];
|
2169 |
+
update_post_meta( $post_id, '__wpdm_' . $key, $value );
|
2170 |
+
}
|
2171 |
+
|
2172 |
+
if ( isset( $package_data['cats'] ) ) {
|
2173 |
+
wp_set_post_terms( $post_id, $package_data['cats'], 'wpdmcategory' );
|
2174 |
+
}
|
2175 |
+
|
2176 |
+
if ( isset( $package_data['featured_image'] ) ) {
|
2177 |
+
|
2178 |
+
$wp_filetype = wp_check_filetype( wp_basename( $package_data['featured_image'] ), null );
|
2179 |
+
|
2180 |
+
if ( __::is_url( $package_data['featured_image'] ) ) {
|
2181 |
+
$upload_dir = wp_upload_dir();
|
2182 |
+
$file_path = $upload_dir['path'] . '/' . sanitize_file_name( $package_data['post_title'] ) . '.' . $wp_filetype['ext'];
|
2183 |
+
//$data = remote_get($package_data['featured_image']);
|
2184 |
+
//$ret = copy($package_data['featured_image'], $file_path);
|
2185 |
+
//if(!$ret) wpdmdd($package_data['featured_image']);
|
2186 |
+
file_put_contents( $file_path, wpdm_remote_get( $package_data['featured_image'] ) );
|
2187 |
+
$package_data['featured_image'] = $file_path;
|
2188 |
+
}
|
2189 |
+
|
2190 |
+
$mime_type = '';
|
2191 |
+
|
2192 |
+
if ( isset( $wp_filetype['type'] ) && $wp_filetype['type'] ) {
|
2193 |
+
$mime_type = $wp_filetype['type'];
|
2194 |
+
}
|
2195 |
+
unset( $wp_filetype );
|
2196 |
+
$attachment = array(
|
2197 |
+
'post_mime_type' => $mime_type,
|
2198 |
+
'post_parent' => $post_id,
|
2199 |
+
'post_title' => wp_basename( $package_data['featured_image'] ),
|
2200 |
+
'post_status' => 'inherit'
|
2201 |
+
);
|
2202 |
+
$attachment_id = wp_insert_attachment( $attachment, $package_data['featured_image'], $post_id );
|
2203 |
+
unset( $attachment );
|
2204 |
+
|
2205 |
+
if ( ! is_wp_error( $attachment_id ) ) {
|
2206 |
+
$attachment_data = wp_generate_attachment_metadata( $attachment_id, $package_data['featured_image'] );
|
2207 |
+
wp_update_attachment_metadata( $attachment_id, $attachment_data );
|
2208 |
+
unset( $attachment_data );
|
2209 |
+
set_post_thumbnail( $post_id, $attachment_id );
|
2210 |
+
}
|
2211 |
+
}
|
2212 |
+
|
2213 |
+
return $post_id;
|
2214 |
+
}
|
2215 |
+
|
2216 |
+
/**
|
2217 |
+
* @param $id
|
2218 |
+
* @param array $atfb
|
2219 |
+
*
|
2220 |
+
* @return string
|
2221 |
+
*/
|
2222 |
+
public static function favBtn( $id, $atfb = array(), $count = true ) {
|
2223 |
+
if ( empty( $atfb ) ) {
|
2224 |
+
$atfb = array(
|
2225 |
+
'size' => '',
|
2226 |
+
'a2f_label' => "<i class='fa fa-heart'></i> " . __( "Add to favourite", "download-manager" ),
|
2227 |
+
'rff_label' => "<i class='fa fa-heart'></i> " . __( "Remove from favourite", "download-manager" )
|
2228 |
+
);
|
2229 |
+
}
|
2230 |
+
$atfb = apply_filters( "wpdm_fav_btn", $atfb, $id );
|
2231 |
+
$myfavs = maybe_unserialize( get_user_meta( get_current_user_id(), '__wpdm_favs', true ) );
|
2232 |
+
$ufavs = maybe_unserialize( get_post_meta( $id, '__wpdm_favs', true ) );
|
2233 |
+
$pfc = is_array( $ufavs ) ? count( $ufavs ) : 0;
|
2234 |
+
$btnclass = is_array( $myfavs ) && in_array( $id, $myfavs ) ? 'btn-danger' : 'btn-secondary';
|
2235 |
+
$label = is_array( $myfavs ) && in_array( $id, $myfavs ) ? $atfb['rff_label'] : $atfb['a2f_label'];
|
2236 |
+
extract( $atfb );
|
2237 |
+
if ( $count ) {
|
2238 |
+
return "<div class='btn-group'><button type='button' data-alabel=\"{$atfb['a2f_label']}\" data-rlabel=\"{$atfb['rff_label']}\" data-package='{$id}' class='btn btn-wpdm-a2f {$btnclass} {$size} btn-simple'>{$label}</button><button class='btn btn-secondary btn-simple {$size}' disabled='disabled'>{$pfc}</button></div>";
|
2239 |
+
} else {
|
2240 |
+
return "<button type='button' data-alabel=\"{$atfb['a2f_label']}\" data-rlabel=\"{$atfb['rff_label']}\" data-package='{$id}' class='btn btn-wpdm-a2f {$btnclass} {$size} btn-simple'>{$label}</button>";
|
2241 |
+
}
|
2242 |
+
|
2243 |
+
}
|
2244 |
+
|
2245 |
+
/**
|
2246 |
+
* Shows favourite count
|
2247 |
+
*
|
2248 |
+
* @param $id
|
2249 |
+
*
|
2250 |
+
* @return int
|
2251 |
+
*/
|
2252 |
+
public static function favCount( $id ) {
|
2253 |
+
$ufavs = maybe_unserialize( get_post_meta( $id, '__wpdm_favs', true ) );
|
2254 |
+
$pfc = is_array( $ufavs ) ? count( $ufavs ) : 0;
|
2255 |
+
|
2256 |
+
return $pfc;
|
2257 |
+
}
|
2258 |
+
|
2259 |
+
/**
|
2260 |
+
* @param $ID
|
2261 |
+
* @param $emails
|
2262 |
+
* @param string $names
|
2263 |
+
* @param int $usageLimit
|
2264 |
+
* @param int $expireTime
|
2265 |
+
*
|
2266 |
+
* @usage mail package link to specified email address
|
2267 |
+
* @since 4.7.4
|
2268 |
+
*/
|
2269 |
+
static function emailDownloadLink( $ID, $emails, $names = '', $usageLimit = 3, $expireTime = 604800 ) {
|
2270 |
+
if ( ! is_array( $emails ) ) {
|
2271 |
+
$emails = explode( ",", $emails );
|
2272 |
+
}
|
2273 |
+
if ( ! is_array( $names ) ) {
|
2274 |
+
$names = explode( ",", $names );
|
2275 |
+
}
|
2276 |
+
$title = get_the_title( $ID );
|
2277 |
+
$banner = get_the_post_thumbnail_url( $ID, array( 600, 400 ) );
|
2278 |
+
$logo = get_site_icon_url();
|
2279 |
+
foreach ( $emails as $index => $email ) {
|
2280 |
+
$download_link = WPDM()->package->expirableDownloadLink( $ID, $usageLimit, $expireTime );
|
2281 |
+
$download_page_link = WPDM()->package->expirableDownloadPage( $ID, $usageLimit, $expireTime );
|
2282 |
+
$params = array(
|
2283 |
+
'to_email' => $email,
|
2284 |
+
'name' => isset( $names[ $index ] ) ? $names[ $index ] : '',
|
2285 |
+
'package_name' => $title,
|
2286 |
+
'download_url' => $download_link,
|
2287 |
+
'download_page_url' => $download_page_link,
|
2288 |
+
'img_logo' => $logo,
|
2289 |
+
'banner' => $banner
|
2290 |
+
);
|
2291 |
+
\WPDM\__\Email::send( "email-lock", $params );
|
2292 |
+
}
|
2293 |
+
}
|
2294 |
+
|
2295 |
+
/**
|
2296 |
+
* Check if specified link or page template have the tag
|
2297 |
+
*
|
2298 |
+
* @param null $template
|
2299 |
+
* @param $tag
|
2300 |
+
*
|
2301 |
+
* @return bool|string
|
2302 |
+
*/
|
2303 |
+
static function templateHasTag( $template = null, $tag = '' ) {
|
2304 |
+
if ( ! $template ) {
|
2305 |
+
return true;
|
2306 |
+
} else if ( is_string( $tag ) ) {
|
2307 |
+
return substr_count( $template, "[{$tag}]" );
|
2308 |
+
} else if ( is_array( $tag ) ) {
|
2309 |
+
foreach ( $tag as $t ) {
|
2310 |
+
if ( substr_count( $template, "[{$t}]" ) ) {
|
2311 |
+
return true;
|
2312 |
+
}
|
2313 |
+
}
|
2314 |
+
}
|
2315 |
+
|
2316 |
+
return false;
|
2317 |
+
|
2318 |
+
}
|
2319 |
+
|
2320 |
+
/**
|
2321 |
+
* Returns package icon
|
2322 |
+
*
|
2323 |
+
* @param $ID
|
2324 |
+
*
|
2325 |
+
* @return string
|
2326 |
+
*/
|
2327 |
+
static function icon( $ID, $html = false, $class = '' ) {
|
2328 |
+
$icon = get_post_meta( $ID, '__wpdm_icon', true );
|
2329 |
+
if ( $icon == '' ) {
|
2330 |
+
$file_types = WPDM()->package->fileTypes( $ID, false );
|
2331 |
+
if ( count( $file_types ) ) {
|
2332 |
+
if ( count( $file_types ) == 1 ) {
|
2333 |
+
$tmpavar = $file_types;
|
2334 |
+
$ext = $tmpvar = array_shift( $tmpavar );
|
2335 |
+
} else {
|
2336 |
+
$ext = 'zip';
|
2337 |
+
}
|
2338 |
+
} else {
|
2339 |
+
$ext = "unknown";
|
2340 |
+
}
|
2341 |
+
if ( $ext === '' ) {
|
2342 |
+
$ext = 'wpdm';
|
2343 |
+
}
|
2344 |
+
$icon = FileSystem::fileTypeIcon( $ext );
|
2345 |
+
}
|
2346 |
+
if ( $html ) {
|
2347 |
+
$icon = "<img src='{$icon}' alt='Icon' class='$class' />";
|
2348 |
+
}
|
2349 |
+
|
2350 |
+
return apply_filters( "wpdm_package_icon", $icon, $ID );
|
2351 |
+
}
|
2352 |
+
|
2353 |
+
/**
|
2354 |
+
* Create a copy of a given package
|
2355 |
+
*
|
2356 |
+
* @param $ID
|
2357 |
+
*
|
2358 |
+
* @return int|\WP_Error
|
2359 |
+
*/
|
2360 |
+
static function copy( $ID, $author = null, $new_meta = array() ) {
|
2361 |
+
$old_pack = (array) get_post( $ID );
|
2362 |
+
$package = array(
|
2363 |
+
'post_title' => $old_pack['post_title'],
|
2364 |
+
'post_content' => $old_pack['post_content'],
|
2365 |
+
'post_status' => $old_pack['post_status'],
|
2366 |
+
'comment_status' => $old_pack['comment_status'],
|
2367 |
+
'ping_status' => $old_pack['ping_status'],
|
2368 |
+
'post_type' => 'wpdmpro'
|
2369 |
+
);
|
2370 |
+
|
2371 |
+
if ( $author ) {
|
2372 |
+
$package['post_author'] = $author;
|
2373 |
+
}
|
2374 |
+
$new_ID = wp_insert_post( $package );
|
2375 |
+
|
2376 |
+
$meta = get_post_meta( $ID );
|
2377 |
+
|
2378 |
+
foreach ( $meta as $key => $value ) {
|
2379 |
+
foreach ( $value as $v ) {
|
2380 |
+
update_post_meta( $new_ID, $key, maybe_unserialize( $v ) );
|
2381 |
+
}
|
2382 |
+
}
|
2383 |
+
if ( is_array( $new_meta ) ) {
|
2384 |
+
foreach ( $new_meta as $key => $value ) {
|
2385 |
+
update_post_meta( $new_ID, $key, maybe_unserialize( $value ) );
|
2386 |
+
}
|
2387 |
+
}
|
2388 |
+
|
2389 |
+
return $new_ID;
|
2390 |
+
}
|
2391 |
+
|
2392 |
+
static function dummy() {
|
2393 |
+
$package = array(
|
2394 |
+
'post_title' => __( 'Sample Package', 'download-manager' ),
|
2395 |
+
'post_content' => 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. ',
|
2396 |
+
'excerpt' => 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s',
|
2397 |
+
'post_status' => 'publish',
|
2398 |
+
'download_link' => '<a href="#">Download</a>',
|
2399 |
+
'download_link_extended' => '<a href="#">Download</a>',
|
2400 |
+
);
|
2401 |
+
|
2402 |
+
return $package;
|
2403 |
+
}
|
2404 |
+
|
2405 |
+
/**
|
2406 |
+
* @param null $ID
|
2407 |
+
*
|
2408 |
+
* @return array Additional preview image urls
|
2409 |
+
*/
|
2410 |
+
function additionalPreviews( $ID = null ) {
|
2411 |
+
$ID = $ID ? $ID : $this->ID;
|
2412 |
+
if ( ! $ID && is_singular( 'wpdmpro' ) ) {
|
2413 |
+
$ID = get_the_ID();
|
2414 |
+
}
|
2415 |
+
if ( ! $ID ) {
|
2416 |
+
return array();
|
2417 |
+
}
|
2418 |
+
$additional_previews = get_post_meta( $ID, '__wpdm_additional_previews', true );
|
2419 |
+
$previews = array();
|
2420 |
+
foreach ( $additional_previews as $media_id ) {
|
2421 |
+
$previews[] = wp_get_attachment_url( $media_id );
|
2422 |
+
}
|
2423 |
+
|
2424 |
+
return $previews;
|
2425 |
+
}
|
2426 |
+
|
2427 |
+
function getThumbnail( $ID, $FILEID, $size ) {
|
2428 |
+
if ( ! $this->files ) {
|
2429 |
+
$this->files = self::getFiles( $ID, true );
|
2430 |
+
}
|
2431 |
+
$file = wpdm_valueof( $this->files, $FILEID );
|
2432 |
+
|
2433 |
+
$imgext = array( 'png', 'jpg', 'jpeg', 'gif' );
|
2434 |
+
$ext = FileSystem::fileExt( $file );
|
2435 |
+
$thumb = '';
|
2436 |
+
$abspath = WPDM()->package->locateFile( $file );
|
2437 |
+
|
2438 |
+
if ( in_array( $ext, $imgext ) && $abspath ) {
|
2439 |
+
$thumb = FileSystem::imageThumbnail( $abspath, $size[0], $size[1], WPDM_USE_GLOBAL, true );
|
2440 |
+
} else if ( $ext === 'svg' ) {
|
2441 |
+
$thumb = str_replace( ABSPATH, home_url( '/' ), $file );
|
2442 |
+
} else if ( strtolower( $ext ) === 'pdf' && class_exists( 'Imagick' ) ) {
|
2443 |
+
$thumb = FileSystem::pdfThumbnail( $file, md5( $file ) );
|
2444 |
+
} else {
|
2445 |
+
$thumb = FileSystem::fileTypeIcon( $ext );
|
2446 |
+
}
|
2447 |
+
|
2448 |
+
return apply_filters( "wpdm_file_thumbnail", $thumb, [
|
2449 |
+
'file' => $file,
|
2450 |
+
'FILEID' => $FILEID,
|
2451 |
+
'ID' => $ID,
|
2452 |
+
'size' => $size
|
2453 |
+
] );
|
2454 |
+
}
|
2455 |
+
|
2456 |
+
function locateFile( $file ) {
|
2457 |
+
if ( file_exists( $file ) ) {
|
2458 |
+
return $file;
|
2459 |
+
}
|
2460 |
+
if ( file_exists( UPLOAD_DIR . $file ) ) {
|
2461 |
+
return UPLOAD_DIR . $file;
|
2462 |
+
}
|
2463 |
+
|
2464 |
+
return false;
|
2465 |
+
}
|
2466 |
+
|
2467 |
+
function addViewCount() {
|
2468 |
+
if ( isset( $_REQUEST['__wpdm_view_count'] ) && wp_verify_nonce( $_REQUEST['__wpdm_view_count'], NONCE_KEY ) ) {
|
2469 |
+
|
2470 |
+
$id = (int) ( $_REQUEST['id'] );
|
2471 |
+
$views = (int) get_post_meta( $id, '__wpdm_view_count', true );
|
2472 |
+
update_post_meta( $id, '__wpdm_view_count', $views + 1 );
|
2473 |
+
wp_send_json( [ 'views' => $views + 1 ] );
|
2474 |
+
}
|
2475 |
+
}
|
2476 |
+
|
2477 |
+
|
2478 |
+
/**
|
2479 |
+
* @usage Find similar packages
|
2480 |
+
*
|
2481 |
+
* @param null $package_id
|
2482 |
+
* @param int $count
|
2483 |
+
* @param bool|true $html
|
2484 |
+
*
|
2485 |
+
* @return array|bool|string
|
2486 |
+
*/
|
2487 |
+
function similarPackages( $package_id = null, $count = 5, $html = true ) {
|
2488 |
+
$id = $package_id ? $package_id : get_the_ID();
|
2489 |
+
if ( is_array( $package_id ) ) {
|
2490 |
+
$id = $package_id['ID'];
|
2491 |
+
}
|
2492 |
+
$tags = wp_get_post_terms( $id, 'wpdmtag' );
|
2493 |
+
$cats = wp_get_post_terms( $id, 'wpdmcategory' );
|
2494 |
+
$posts = array();
|
2495 |
+
if ( $tags ) {
|
2496 |
+
$tag_ids = array();
|
2497 |
+
foreach ( $tags as $individual_tag ) {
|
2498 |
+
$tag_ids[] = $individual_tag->term_id;
|
2499 |
+
}
|
2500 |
+
foreach ( $cats as $individual_cat ) {
|
2501 |
+
$cat_ids[] = $individual_cat->term_id;
|
2502 |
+
}
|
2503 |
+
$args = array(
|
2504 |
+
'post_type' => 'wpdmpro',
|
2505 |
+
'tax_query' => [
|
2506 |
+
[
|
2507 |
+
'taxonomy' => 'wpdmtag',
|
2508 |
+
'field' => 'id',
|
2509 |
+
'terms' => $tag_ids,
|
2510 |
+
'operator' => 'IN'
|
2511 |
+
],
|
2512 |
+
[
|
2513 |
+
'taxonomy' => 'wpdmcategory',
|
2514 |
+
'field' => 'id',
|
2515 |
+
'terms' => $cat_ids,
|
2516 |
+
'operator' => 'IN'
|
2517 |
+
],
|
2518 |
+
'relation' => 'OR'
|
2519 |
+
],
|
2520 |
+
'post__not_in' => array( $id ),
|
2521 |
+
'posts_per_page' => $count
|
2522 |
+
);
|
2523 |
+
|
2524 |
+
$posts = get_posts( $args );
|
2525 |
+
|
2526 |
+
if ( ! $html ) {
|
2527 |
+
return $posts;
|
2528 |
+
}
|
2529 |
+
|
2530 |
+
$html = "";
|
2531 |
+
//Filter hook to change related packages/downloads template
|
2532 |
+
$template = apply_filters( "wpdm_replated_package_template", "link-template-panel.php", $package_id );
|
2533 |
+
$cols = apply_filters( "wpdm_replated_package_columns", 6, $package_id );
|
2534 |
+
foreach ( $posts as $p ) {
|
2535 |
+
|
2536 |
+
$package['ID'] = $p->ID;
|
2537 |
+
$package['post_title'] = $p->post_title;
|
2538 |
+
$package['post_content'] = $p->post_content;
|
2539 |
+
$package['post_excerpt'] = $p->post_excerpt;
|
2540 |
+
$html .= "<div class='col-md-{$cols}'>" . wpdm_fetch_template( $template, $package, 'link' ) . "</div>";
|
2541 |
+
|
2542 |
+
}
|
2543 |
+
}
|
2544 |
+
if ( count( $posts ) == 0 ) {
|
2545 |
+
$html = "<div class='col-md-12'><div class='alert alert-info'>" . __( "No related download found!", "download-manager" ) . "</div> </div>";
|
2546 |
+
}
|
2547 |
+
$html = "<div class='w3eden'><div class='row'>" . $html . "</div></div>";
|
2548 |
+
wp_reset_query();
|
2549 |
+
|
2550 |
+
return $html;
|
2551 |
+
}
|
2552 |
+
|
2553 |
+
function search( $keyword = '' ) {
|
2554 |
+
$keyword = wpdm_query_var( 'search' ) ?: $keyword;
|
2555 |
+
if ( $keyword ) {
|
2556 |
+
$query = new Query();
|
2557 |
+
$query->search( $keyword );
|
2558 |
+
if ( wpdm_query_var( 'premium', 'int' ) > 0 ) {
|
2559 |
+
$query->meta( '__wpdm_base_price', 0, '>' );
|
2560 |
+
$query->meta_relation( 'AND' );
|
2561 |
+
}
|
2562 |
+
$query->process();
|
2563 |
+
$packages = $query->packages();
|
2564 |
+
foreach ( $packages as &$package ) {
|
2565 |
+
$package = (object) [
|
2566 |
+
'ID' => $package->ID,
|
2567 |
+
'post_title' => $package->post_title,
|
2568 |
+
'post_content' => $package->post_content
|
2569 |
+
];
|
2570 |
+
}
|
2571 |
+
if ( wpdm_query_var( 'premium', 'int' ) > 0 && function_exists( 'wpdmpp_product_license_options' ) ) {
|
2572 |
+
foreach ( $packages as &$package ) {
|
2573 |
+
$licenses = wpdmpp_product_license_options( $package->ID );
|
2574 |
+
$package->licenses = count( $licenses ) > 0 ? $licenses : null;
|
2575 |
+
}
|
2576 |
+
}
|
2577 |
+
wp_send_json( [ 'total' => $query->count, 'packages' => $packages, 'q' => $query->params ] );
|
2578 |
+
}
|
2579 |
+
}
|
2580 |
|
2581 |
|
2582 |
}
|
src/__/FileSystem.php
CHANGED
@@ -91,7 +91,7 @@ class FileSystem
|
|
91 |
$fsize = filesize($filepath);
|
92 |
else
|
93 |
$fsize = 0;
|
94 |
-
$
|
95 |
|
96 |
nocache_headers();
|
97 |
header("X-Robots-Tag: noindex, nofollow", true);
|
@@ -116,7 +116,7 @@ class FileSystem
|
|
116 |
}
|
117 |
|
118 |
if ((isset($extras['play']) && strpos($_SERVER['HTTP_USER_AGENT'], "Safari")) || get_option('__wpdm_download_resume', 1) == 2) {
|
119 |
-
header("Content-Length: " . $
|
120 |
header("Content-disposition: attachment;filename=\"{$filename}\"");
|
121 |
TempStorage::set("download." . wpdm_get_client_ip(), 1, 60);
|
122 |
readfile($filepath);
|
@@ -136,17 +136,17 @@ class FileSystem
|
|
136 |
$new_length = $fsize - $set_pointer;
|
137 |
|
138 |
header("Accept-Ranges: bytes");
|
139 |
-
header("Accept-Ranges: 0
|
140 |
$proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
|
141 |
header("{$proto} 206 Partial Content");
|
142 |
|
143 |
header("Content-Length: $new_length");
|
144 |
-
header("Content-Range: bytes $
|
145 |
|
146 |
fseek($file, $set_pointer);
|
147 |
|
148 |
} else {
|
149 |
-
header("Content-Length: " . $
|
150 |
}
|
151 |
$packet = 1;
|
152 |
|
@@ -181,6 +181,7 @@ class FileSystem
|
|
181 |
|
182 |
}
|
183 |
|
|
|
184 |
/**
|
185 |
* @usage Download any content as a file
|
186 |
* @param $filename
|
91 |
$fsize = filesize($filepath);
|
92 |
else
|
93 |
$fsize = 0;
|
94 |
+
$orig_size = $fsize;
|
95 |
|
96 |
nocache_headers();
|
97 |
header("X-Robots-Tag: noindex, nofollow", true);
|
116 |
}
|
117 |
|
118 |
if ((isset($extras['play']) && strpos($_SERVER['HTTP_USER_AGENT'], "Safari")) || get_option('__wpdm_download_resume', 1) == 2) {
|
119 |
+
header("Content-Length: " . $orig_size);
|
120 |
header("Content-disposition: attachment;filename=\"{$filename}\"");
|
121 |
TempStorage::set("download." . wpdm_get_client_ip(), 1, 60);
|
122 |
readfile($filepath);
|
136 |
$new_length = $fsize - $set_pointer;
|
137 |
|
138 |
header("Accept-Ranges: bytes");
|
139 |
+
header("Accept-Ranges: 0-".($orig_size - 1));
|
140 |
$proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
|
141 |
header("{$proto} 206 Partial Content");
|
142 |
|
143 |
header("Content-Length: $new_length");
|
144 |
+
header("Content-Range: bytes $set_pointer-".($fsize-1)."/$orig_size");
|
145 |
|
146 |
fseek($file, $set_pointer);
|
147 |
|
148 |
} else {
|
149 |
+
header("Content-Length: " . $orig_size);
|
150 |
}
|
151 |
$packet = 1;
|
152 |
|
181 |
|
182 |
}
|
183 |
|
184 |
+
|
185 |
/**
|
186 |
* @usage Download any content as a file
|
187 |
* @param $filename
|
src/wpdm-functions.php
CHANGED
@@ -130,11 +130,8 @@ function wpdm_package_size($id)
|
|
130 |
*/
|
131 |
function wpdm_file_size($file)
|
132 |
{
|
133 |
-
|
134 |
-
|
135 |
-
else if (file_exists(UPLOAD_DIR . $file))
|
136 |
-
$size = filesize(UPLOAD_DIR . $file);
|
137 |
-
else $size = 0;
|
138 |
$size = $size / 1024;
|
139 |
if ($size > 1024) $size = number_format($size / 1024, 2) . ' MB';
|
140 |
else $size = number_format($size, 2) . ' KB';
|
130 |
*/
|
131 |
function wpdm_file_size($file)
|
132 |
{
|
133 |
+
$file = WPDM()->fileSystem->absPath($file);
|
134 |
+
$size = filesize($file);
|
|
|
|
|
|
|
135 |
$size = $size / 1024;
|
136 |
if ($size > 1024) $size = number_format($size / 1024, 2) . ' MB';
|
137 |
else $size = number_format($size, 2) . ' KB';
|
src/wpdm-start-download.php
CHANGED
@@ -110,6 +110,7 @@ else {
|
|
110 |
}*/
|
111 |
|
112 |
$filepath = WPDM()->fileSystem->absPath($indfile, $package['ID']);
|
|
|
113 |
if(!$filepath)
|
114 |
Messages::fullPage('Error!', "<div class='card bg-danger text-white p-4'>" . __("Sorry! File not found!", "download-manager") . "</div>", 'error');
|
115 |
//$plock = get_wpdm_meta($file['id'],'password_lock',true);
|
110 |
}*/
|
111 |
|
112 |
$filepath = WPDM()->fileSystem->absPath($indfile, $package['ID']);
|
113 |
+
|
114 |
if(!$filepath)
|
115 |
Messages::fullPage('Error!', "<div class='card bg-danger text-white p-4'>" . __("Sorry! File not found!", "download-manager") . "</div>", 'error');
|
116 |
//$plock = get_wpdm_meta($file['id'],'password_lock',true);
|