1 <?php
2 3 4 5 6 7 8 9 10
11
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 16 17 18 19 20 21
22 function edd_is_test_mode() {
23 global $edd_options;
24
25 if ( ! isset( $edd_options['test_mode'] ) || is_null( $edd_options['test_mode'] ) )
26 $ret = false;
27 else
28 $ret = true;
29
30 return (bool) apply_filters( 'edd_is_test_mode', $ret );
31 }
32
33 34 35 36 37 38 39
40 function edd_no_guest_checkout() {
41 global $edd_options;
42
43 if ( isset( $edd_options['logged_in_only'] ) )
44 $ret = true;
45 else
46 $ret = false;
47
48 return (bool) apply_filters( 'edd_no_guest_checkout', $ret );
49 }
50
51 52 53 54 55 56 57
58 function edd_logged_in_only() {
59 global $edd_options;
60
61 if ( isset( $edd_options['logged_in_only'] ) )
62 $ret = true;
63 else
64 $ret = false;
65
66 return (bool) apply_filters( 'edd_logged_in_only', $ret );
67 }
68
69 70 71 72 73 74
75 function edd_straight_to_checkout() {
76 global $edd_options;
77 $ret = isset( $edd_options['redirect_on_add'] );
78 return (bool) apply_filters( 'edd_straight_to_checkout', $ret );
79 }
80
81 82 83 84 85 86 87 88
89 function edd_no_redownload() {
90 global $edd_options;
91
92 if ( isset( $edd_options['disable_redownload'] ) )
93 return true;
94
95 return (bool) apply_filters( 'edd_no_redownload', false );
96 }
97
98 99 100 101 102 103 104
105 function edd_is_cc_verify_enabled() {
106 global $edd_options;
107
108 $ret = true;
109
110 111 112 113
114
115 $gateways = edd_get_enabled_payment_gateways();
116
117 if ( count( $gateways ) == 1 && ! isset( $gateways['paypal'] ) && ! isset( $gateways['manual'] ) )
118 $ret = true;
119 else if ( count( $gateways ) == 1 )
120 $ret = false;
121 else if ( count( $gateways ) == 2 && isset( $gateways['paypal'] ) && isset( $gateways['manual'] ) )
122 $ret = false;
123
124 if ( isset( $edd_options['edd_is_cc_verify_enabled'] ) )
125 $ret = false;
126
127 return (bool) apply_filters( 'edd_verify_credit_cards', $ret );
128 }
129
130 131 132 133 134 135 136 137 138
139 function edd_is_odd( $int ) {
140 return (bool) ( $int & 1 );
141 }
142
143 144 145 146 147 148 149 150 151
152 function edd_get_file_extension( $str ) {
153 $parts = explode( '.', $str );
154 return end( $parts );
155 }
156
157 158 159 160 161 162 163
164 function edd_string_is_image_url( $str ) {
165 $ext = edd_get_file_extension( $str );
166
167 switch( strtolower( $ext ) ) {
168 case 'jpg';
169 $return = true;
170 break;
171 case 'png';
172 $return = true;
173 break;
174 case 'gif';
175 $return = true;
176 break;
177 default:
178 $return = false;
179 break;
180 }
181
182 return (bool) apply_filters( 'edd_string_is_image', $return, $str );
183 }
184
185 186 187 188 189 190 191 192
193 function edd_get_ip() {
194 if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
195
196 $ip = $_SERVER['HTTP_CLIENT_IP'];
197 } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
198
199 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
200 } else {
201 $ip = $_SERVER['REMOTE_ADDR'];
202 }
203 return apply_filters( 'edd_get_ip', $ip );
204 }
205
206 207 208 209 210 211
212 function edd_get_currencies() {
213 $currencies = array(
214 'USD' => __('US Dollars ($)', 'edd'),
215 'EUR' => __('Euros (€)', 'edd'),
216 'GBP' => __('Pounds Sterling (£)', 'edd'),
217 'AUD' => __('Australian Dollars ($)', 'edd'),
218 'BRL' => __('Brazilian Real (R$)', 'edd'),
219 'CAD' => __('Canadian Dollars ($)', 'edd'),
220 'CZK' => __('Czech Koruna', 'edd'),
221 'DKK' => __('Danish Krone', 'edd'),
222 'HKD' => __('Hong Kong Dollar ($)', 'edd'),
223 'HUF' => __('Hungarian Forint', 'edd'),
224 'ILS' => __('Israeli Shekel', 'edd'),
225 'JPY' => __('Japanese Yen (¥)', 'edd'),
226 'MYR' => __('Malaysian Ringgits', 'edd'),
227 'MXN' => __('Mexican Peso ($)', 'edd'),
228 'NZD' => __('New Zealand Dollar ($)', 'edd'),
229 'NOK' => __('Norwegian Krone', 'edd'),
230 'PHP' => __('Philippine Pesos', 'edd'),
231 'PLN' => __('Polish Zloty', 'edd'),
232 'SGD' => __('Singapore Dollar ($)', 'edd'),
233 'SEK' => __('Swedish Krona', 'edd'),
234 'CHF' => __('Swiss Franc', 'edd'),
235 'TWD' => __('Taiwan New Dollars', 'edd'),
236 'THB' => __('Thai Baht', 'edd'),
237 'INR' => __('Indian Rupee', 'edd'),
238 'TRY' => __('Turkish Lira', 'edd'),
239 'RIAL' => __('Iranian Rial', 'edd')
240 );
241
242 return apply_filters( 'edd_currencies', $currencies );
243 }
244
245 246 247 248 249 250
251 function edd_get_country_list() {
252 $countries = array(
253 'US' => 'United States',
254 'CA' => 'Canada',
255 'GB' => 'United Kingdom',
256 'AD' => 'Andorra',
257 'AE' => 'United Arab Emirates',
258 'AF' => 'Afghanistan',
259 'AG' => 'Antigua and Barbuda',
260 'AI' => 'Anguilla',
261 'AL' => 'Albania',
262 'AM' => 'Armenia',
263 'AN' => 'Netherlands Antilles',
264 'AO' => 'Angola',
265 'AQ' => 'Antarctica',
266 'AR' => 'Argentina',
267 'AS' => 'American Samoa',
268 'AT' => 'Austria',
269 'AU' => 'Australia',
270 'AW' => 'Aruba',
271 'AZ' => 'Azerbaijan',
272 'BA' => 'Bosnia and Herzegovina',
273 'BB' => 'Barbados',
274 'BD' => 'Bangladesh',
275 'BE' => 'Belgium',
276 'BF' => 'Burkina Faso',
277 'BG' => 'Bulgaria',
278 'BH' => 'Bahrain',
279 'BI' => 'Burundi',
280 'BJ' => 'Benin',
281 'BM' => 'Bermuda',
282 'BN' => 'Brunei Darrussalam',
283 'BO' => 'Bolivia',
284 'BR' => 'Brazil',
285 'BS' => 'Bahamas',
286 'BT' => 'Bhutan',
287 'BV' => 'Bouvet Island',
288 'BW' => 'Botswana',
289 'BY' => 'Belarus',
290 'BZ' => 'Belize',
291 'CC' => 'Cocos Islands',
292 'CD' => 'Congo, Democratic People\'s Republic',
293 'CF' => 'Central African Republic',
294 'CG' => 'Congo, Republic of',
295 'CH' => 'Switzerland',
296 'CI' => 'Cote d\'Ivoire',
297 'CK' => 'Cook Islands',
298 'CL' => 'Chile',
299 'CM' => 'Cameroon',
300 'CN' => 'China',
301 'CO' => 'Colombia',
302 'CR' => 'Costa Rica',
303 'CU' => 'Cuba',
304 'CV' => 'Cap Verde',
305 'CX' => 'Christmas Island',
306 'CY' => 'Cyprus Island',
307 'CZ' => 'Czech Republic',
308 'DE' => 'Germany',
309 'DJ' => 'Djibouti',
310 'DK' => 'Denmark',
311 'DM' => 'Dominica',
312 'DO' => 'Dominican Republic',
313 'DZ' => 'Algeria',
314 'EC' => 'Ecuador',
315 'EE' => 'Estonia',
316 'EG' => 'Egypt',
317 'EH' => 'Western Sahara',
318 'ER' => 'Eritrea',
319 'ES' => 'Spain',
320 'ET' => 'Ethiopia',
321 'FI' => 'Finland',
322 'FJ' => 'Fiji',
323 'FK' => 'Falkland Islands',
324 'FM' => 'Micronesia',
325 'FO' => 'Faroe Islands',
326 'FR' => 'France',
327 'GA' => 'Gabon',
328 'GD' => 'Grenada',
329 'GE' => 'Georgia',
330 'GF' => 'French Guiana',
331 'GG' => 'Guernsey',
332 'GH' => 'Ghana',
333 'GI' => 'Gibraltar',
334 'GL' => 'Greenland',
335 'GM' => 'Gambia',
336 'GN' => 'Guinea',
337 'GP' => 'Guadeloupe',
338 'GQ' => 'Equatorial Guinea',
339 'GR' => 'Greece',
340 'GS' => 'South Georgia',
341 'GT' => 'Guatemala',
342 'GU' => 'Guam',
343 'GW' => 'Guinea-Bissau',
344 'GY' => 'Guyana',
345 'HK' => 'Hong Kong',
346 'HM' => 'Heard and McDonald Islands',
347 'HN' => 'Honduras',
348 'HR' => 'Croatia/Hrvatska',
349 'HT' => 'Haiti',
350 'HU' => 'Hungary',
351 'ID' => 'Indonesia',
352 'IE' => 'Ireland',
353 'IL' => 'Israel',
354 'IM' => 'Isle of Man',
355 'IN' => 'India',
356 'IO' => 'British Indian Ocean Territory',
357 'IQ' => 'Iraq',
358 'IR' => 'Iran',
359 'IS' => 'Iceland',
360 'IT' => 'Italy',
361 'JE' => 'Jersey',
362 'JM' => 'Jamaica',
363 'JO' => 'Jordan',
364 'JP' => 'Japan',
365 'KE' => 'Kenya',
366 'KG' => 'Kyrgyzstan',
367 'KH' => 'Cambodia',
368 'KI' => 'Kiribati',
369 'KM' => 'Comoros',
370 'KN' => 'Saint Kitts and Nevis',
371 'KP' => 'South Korea',
372 'KR' => 'North Korea',
373 'KW' => 'Kuwait',
374 'KY' => 'Cayman Islands',
375 'KZ' => 'Kazakhstan',
376 'LA' => 'Lao People\'s Democratic Republic',
377 'LB' => 'Lebanon',
378 'LC' => 'Saint Lucia',
379 'LI' => 'Liechtenstein',
380 'LK' => 'Sri Lanka',
381 'LR' => 'Liberia',
382 'LS' => 'Lesotho',
383 'LT' => 'Lithuania',
384 'LU' => 'Luxembourgh',
385 'LV' => 'Latvia',
386 'LY' => 'Libyan Arab Jamahiriya',
387 'MA' => 'Morocco',
388 'MC' => 'Monaco',
389 'ME' => 'Montenegro',
390 'MD' => 'Moldova, Republic of',
391 'MG' => 'Madagascar',
392 'MH' => 'Marshall Islands',
393 'MK' => 'Macedonia',
394 'ML' => 'Mali',
395 'MM' => 'Myanmar',
396 'MN' => 'Mongolia',
397 'MO' => 'Macau',
398 'MP' => 'Northern Mariana Islands',
399 'MQ' => 'Martinique',
400 'MR' => 'Mauritania',
401 'MS' => 'Montserrat',
402 'MT' => 'Malta',
403 'MU' => 'Mauritius',
404 'Mv' => 'Maldives',
405 'MW' => 'malawi',
406 'MX' => 'Mexico',
407 'MY' => 'Malaysia',
408 'MZ' => 'Mozambique',
409 'NA' => 'Namibia',
410 'NC' => 'New Caledonia',
411 'NE' => 'Niger',
412 'NF' => 'Norfolk Island',
413 'NG' => 'Nigeria',
414 'NI' => 'Nicaragua',
415 'NL' => 'Netherlands',
416 'NO' => 'Norway',
417 'NP' => 'Nepal',
418 'NR' => 'Nauru',
419 'NU' => 'Niue',
420 'NZ' => 'New Zealand',
421 'OM' => 'Oman',
422 'PA' => 'Panama',
423 'PE' => 'Peru',
424 'PF' => 'French Polynesia',
425 'PG' => 'papua New Guinea',
426 'PH' => 'Phillipines',
427 'PK' => 'Pakistan',
428 'PL' => 'Poland',
429 'PM' => 'St. Pierre and Miquelon',
430 'PN' => 'Pitcairn Island',
431 'PR' => 'Puerto Rico',
432 'PS' => 'Palestinian Territories',
433 'PT' => 'Portugal',
434 'PW' => 'Palau',
435 'PY' => 'Paraguay',
436 'QA' => 'Qatar',
437 'RE' => 'Reunion Island',
438 'RO' => 'Romania',
439 'RS' => 'Serbia',
440 'RU' => 'Russian Federation',
441 'RW' => 'Rwanda',
442 'SA' => 'Saudi Arabia',
443 'SB' => 'Solomon Islands',
444 'SC' => 'Seychelles',
445 'SD' => 'Sudan',
446 'SE' => 'Sweden',
447 'SG' => 'Singapore',
448 'SH' => 'St. Helena',
449 'SI' => 'Slovenia',
450 'SJ' => 'Svalbard and Jan Mayen Islands',
451 'SK' => 'Slovak Republic',
452 'SL' => 'Sierra Leone',
453 'SM' => 'San Marino',
454 'SN' => 'Senegal',
455 'SO' => 'Somalia',
456 'SR' => 'Suriname',
457 'ST' => 'Sao Tome and Principe',
458 'SV' => 'El Salvador',
459 'SY' => 'Syrian Arab Republic',
460 'SZ' => 'Swaziland',
461 'TC' => 'Turks and Caicos Islands',
462 'TD' => 'Chad',
463 'TF' => 'French Southern Territories',
464 'TG' => 'Togo',
465 'TH' => 'Thailand',
466 'TJ' => 'Tajikistan',
467 'TK' => 'Tokelau',
468 'TM' => 'Turkmenistan',
469 'TN' => 'Tunisia',
470 'TO' => 'Tonga',
471 'TP' => 'East Timor',
472 'TR' => 'Turkey',
473 'TT' => 'Trinidad and Tobago',
474 'TV' => 'Tuvalu',
475 'TW' => 'Taiwan',
476 'TZ' => 'Tanzania',
477 'UA' => 'Ukraine',
478 'UG' => 'Uganda',
479 'UM' => 'US Minor Outlying Islands',
480 'UY' => 'Uruguay',
481 'UZ' => 'Uzbekistan',
482 'VA' => 'Holy See (City Vatican State)',
483 'VC' => 'Saint Vincent and the Grenadines',
484 'VE' => 'Venezuela',
485 'VG' => 'Virgin Islands (British)',
486 'VI' => 'Virgin Islands (USA)',
487 'VN' => 'Vietnam',
488 'VU' => 'Vanuatu',
489 'WF' => 'Wallis and Futuna Islands',
490 'WS' => 'Western Samoa',
491 'YE' => 'Yemen',
492 'YT' => 'Mayotte',
493 'YU' => 'Yugoslavia',
494 'ZA' => 'South Africa',
495 'ZM' => 'Zambia',
496 'ZW' => 'Zimbabwe'
497 );
498
499 return apply_filters( 'edd_countries', $countries );
500 }
501
502 503 504 505 506 507 508
509 function edd_get_states_list() {
510 $states = array(
511 'AL' => 'Alabama',
512 'AK' => 'Alaska',
513 'AZ' => 'Arizona',
514 'AR' => 'Arkansas',
515 'CA' => 'California',
516 'CO' => 'Colorado',
517 'CT' => 'Connecticut',
518 'DE' => 'Delaware',
519 'DC' => 'District of Columbia',
520 'FL' => 'Florida',
521 'GA' => 'Georgia',
522 'HI' => 'Hawaii',
523 'ID' => 'Idaho',
524 'IL' => 'Illinois',
525 'IN' => 'Indiana',
526 'IA' => 'Iowa',
527 'KS' => 'Kansas',
528 'KY' => 'Kentucky',
529 'LA' => 'Louisiana',
530 'ME' => 'Maine',
531 'MD' => 'Maryland',
532 'MA' => 'Massachusetts',
533 'MI' => 'Michigan',
534 'MN' => 'Minnesota',
535 'MS' => 'Mississippi',
536 'MO' => 'Missouri',
537 'MT' => 'Montana',
538 'NE' => 'Nebraksa',
539 'NV' => 'Nevada',
540 'NH' => 'New Hampshire',
541 'NJ' => 'New Jersey',
542 'NM' => 'New Mexico',
543 'NY' => 'New York',
544 'NC' => 'North Carolina',
545 'ND' => 'North Dakota',
546 'OH' => 'Ohio',
547 'OK' => 'Oklahoma',
548 'OR' => 'Oregon',
549 'PA' => 'Pennsylvania',
550 'RI' => 'Rhode Island',
551 'SC' => 'South Carolina',
552 'SD' => 'South Dakota',
553 'TN' => 'Tennessee',
554 'TX' => 'Texas',
555 'UT' => 'Utah',
556 'VT' => 'Vermont',
557 'VA' => 'Virginia',
558 'WA' => 'Washington',
559 'WV' => 'West Virginia',
560 'WI' => 'Wisconsin',
561 'WY' => 'Wyoming',
562 'AS' => 'American Samoa',
563 'CZ' => 'Canal Zone',
564 'CM' => 'Commonwealth of the Northern Mariana Islands',
565 'FM' => 'Federated States of Micronesia',
566 'GU' => 'Guam',
567 'MH' => 'Marshall Islands',
568 'MP' => 'Northern Mariana Islands',
569 'PW' => 'Palau',
570 'PI' => 'Philippine Islands',
571 'PR' => 'Puerto Rico',
572 'TT' => 'Trust Territory of the Pacific Islands',
573 'VI' => 'Virgin Islands',
574 'AA' => 'Armed Forces - Americas',
575 'AE' => 'Armed Forces - Europe, Canada, Middle East, Africa',
576 'AP' => 'Armed Forces - Pacific'
577 );
578
579 return apply_filters( 'edd_us_states', $states );
580 }
581
582 583 584 585 586 587 588
589 function edd_get_provinces_list() {
590 $provinces = array(
591 'AB' => 'Alberta',
592 'BC' => 'British Columbia',
593 'MB' => 'Manitoba',
594 'NB' => 'New Brunswick',
595 'NL' => 'Newfoundland and Labrador',
596 'NS' => 'Nova Scotia',
597 'NT' => 'Northwest Territories',
598 'NU' => 'Nunavut',
599 'ON' => 'Ontario',
600 'PE' => 'Prince Edward Island',
601 'QC' => 'Quebec',
602 'SK' => 'Saskatchewan',
603 'YT' => 'Yukon'
604 );
605
606 return apply_filters( 'edd_canada_provinces', $provinces );
607 }
608
609 610 611 612 613 614 615 616
617 function edd_month_num_to_name( $n ) {
618 $timestamp = mktime( 0, 0, 0, $n, 1, 2005 );
619
620 return date_i18n( "M", $timestamp );
621 }
622
623 624 625 626 627 628
629 function edd_get_php_arg_separator_output() {
630 return ini_get('arg_separator.output');
631 }
632
633 634 635 636 637 638 639
640 function edd_get_current_page_url() {
641 global $post;
642
643 if ( is_front_page() ) :
644 $page_url = home_url();
645 else :
646 $page_url = 'http';
647
648 if ( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" )
649 $page_url .= "s";
650
651 $page_url .= "://";
652
653 if ( $_SERVER["SERVER_PORT"] != "80" )
654 $page_url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
655 else
656 $page_url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
657 endif;
658
659 return apply_filters( 'edd_get_current_page_url', esc_url( $page_url ) );
660 }
661
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
683 function _edd_deprecated_function( $function, $version, $replacement = null, $backtrace = null ) {
684 do_action( 'edd_deprecated_function_run', $function, $replacement, $version );
685
686 $show_errors = current_user_can( 'manage_options' );
687
688
689 if ( WP_DEBUG && apply_filters( 'edd_deprecated_function_trigger_error', $show_errors ) ) {
690 if ( ! is_null( $replacement ) ) {
691 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since Easy Digital Downloads version %2$s! Use %3$s instead.', 'edd' ), $function, $version, $replacement ) );
692 trigger_error( print_r( $backtrace ) );
693
694 }
695 else {
696 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since Easy Digital Downloads version %2$s with no alternative available.', 'edd'), $function, $version ) );
697 trigger_error( print_r($backtrace) );
698
699 }
700 }
701 }
702
703 704 705 706 707 708 709
710 function edd_presstrends() {
711 global $edd_options;
712
713 if ( ! isset( $edd_options['presstrends'] ) )
714 return;
715
716
717 $api_key = '5s8akq2i874z40j69yceyb54qodzg1ux3wtf';
718 $auth = 'xz27f52esm948ogb5xah9bpk4x54usai8';
719
720
721 global $wpdb;
722
723 $data = get_transient( 'presstrends_cache_data' );
724
725 if ( ! $data || $data == '' ) {
726 $api_base = 'http://api.presstrends.io/index.php/api/pluginsites/update/auth/';
727 $url = $api_base . $auth . '/api/' . $api_key . '/';
728
729 $count_posts = wp_count_posts();
730 $count_pages = wp_count_posts( 'page' );
731 $comments_count = wp_count_comments();
732
733
734 if ( function_exists( 'wp_get_theme' ) ) {
735 $theme_data = wp_get_theme();
736 $theme_name = urlencode( $theme_data->Name );
737 } else {
738 $theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
739 $theme_name = $theme_data['Name'];
740 }
741
742 $plugin_name = '&';
743 foreach ( get_plugins() as $plugin_info ) {
744 $plugin_name .= $plugin_info['Name'] . '&';
745 }
746
747 $plugin_data = get_plugin_data( EDD_PLUGIN_FILE );
748 $posts_with_comments = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='post' AND comment_count > 0" );
749 $data = array(
750 'url' => stripslashes( str_replace( array( 'http://', '/', ':' ), '', site_url() ) ),
751 'posts' => $count_posts->publish,
752 'pages' => $count_pages->publish,
753 'comments' => $comments_count->total_comments,
754 'approved' => $comments_count->approved,
755 'spam' => $comments_count->spam,
756 'pingbacks' => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),
757 'post_conversion' => ( $count_posts->publish > 0 && $posts_with_comments > 0 ) ? number_format( ( $posts_with_comments / $count_posts->publish ) * 100, 0, '.', '' ) : 0,
758 'theme_version' => $plugin_data['Version'],
759 'theme_name' => $theme_name,
760 'site_name' => str_replace( ' ', '', get_bloginfo( 'name' ) ),
761 'plugins' => count( get_option( 'active_plugins' ) ),
762 'plugin' => urlencode( $plugin_name ),
763 'wpversion' => get_bloginfo( 'version' ),
764 );
765
766 foreach ( $data as $k => $v ) {
767 $url .= $k . '/' . $v . '/';
768 }
769 wp_remote_get( $url );
770 set_transient( 'presstrends_cache_data', $data, 60 * 60 * 24 );
771 }
772 }
773 add_action( 'admin_init', 'edd_presstrends' );
774
775 776 777 778 779 780 781 782
783 function edd_is_func_disabled( $function ) {
784 $disabled = explode( ',', ini_get( 'disable_functions' ) );
785
786 return in_array( $function, $disabled );
787 }
788
789 790 791 792 793 794 795 796 797 798
799 function edd_let_to_num( $v ) {
800 $l = substr( $v, -1 );
801 $ret = substr( $v, 0, -1 );
802
803 switch ( strtoupper( $l ) ) {
804 case 'P':
805 $ret *= 1024;
806 case 'T':
807 $ret *= 1024;
808 case 'G':
809 $ret *= 1024;
810 case 'M':
811 $ret *= 1024;
812 case 'K':
813 $ret *= 1024;
814 break;
815 }
816
817 return $ret;
818 }
819
820 821 822 823 824 825
826 function edd_get_symlink_url() {
827 $wp_upload_dir = wp_upload_dir();
828 wp_mkdir_p( $wp_upload_dir['basedir'] . '/edd/symlinks' );
829 $url = $wp_upload_dir['baseurl'] . '/edd/symlinks';
830
831 return apply_filters( 'edd_get_symlink_url', $url );
832 }
833
834 835 836 837 838 839
840 function edd_get_symlink_dir() {
841 $wp_upload_dir = wp_upload_dir();
842 wp_mkdir_p( $wp_upload_dir['basedir'] . '/edd/symlinks' );
843 $path = $wp_upload_dir['basedir'] . '/edd/symlinks';
844
845 return apply_filters( 'edd_get_symlink_dir', $path );
846 }
847
848 849 850 851 852 853 854
855 function edd_cleanup_file_symlinks() {
856 $path = edd_get_symlink_dir();
857 $dir = opendir( $path );
858
859 while ( ( $file = readdir( $dir ) ) !== false ) {
860 if ( $file == '.' || $file == '..' )
861 continue;
862
863 $transient = get_transient( md5( $file ) );
864 if ( $transient === false )
865 @unlink( $path . '/' . $file );
866 }
867 }
868 add_action( 'edd_cleanup_file_symlinks', 'edd_cleanup_file_symlinks' );