AddOns.php
5 years ago
Categories.php
3 years ago
Packages.php
1 week ago
Settings.php
5 months ago
Stats.php
4 years ago
Templates.php
2 years ago
Welcome.php
6 months ago
Packages.php
713 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace WPDM\Admin\Menu; |
| 5 | |
| 6 | |
| 7 | use WPDM\__\__; |
| 8 | use WPDM\__\Crypt; |
| 9 | use WPDM\__\FileSystem; |
| 10 | use WPDM\Package\Package; |
| 11 | use WPDM\WordPressDownloadManager; |
| 12 | |
| 13 | class Packages { |
| 14 | |
| 15 | var $sanitize = array( |
| 16 | 'icon' => 'url', |
| 17 | 'version' => 'txt', |
| 18 | 'link_label' => 'txt', |
| 19 | 'package_size' => 'txt', |
| 20 | 'page_template' => 'txt', |
| 21 | 'view_count' => 'int', |
| 22 | 'download_count' => 'int', |
| 23 | 'terms_conditions' => 'kses', |
| 24 | ); |
| 25 | |
| 26 | function __construct() { |
| 27 | |
| 28 | add_action( 'wp_ajax_wpdm_admin_upload_file', array( $this, 'uploadFile' ) ); |
| 29 | add_action( 'save_post', array( $this, 'savePackage' ) ); |
| 30 | |
| 31 | add_action( 'manage_wpdmpro_posts_columns', array( $this, 'columnsTH' ) ); |
| 32 | add_action( 'manage_wpdmpro_posts_custom_column', array( $this, 'columnsTD' ), 10, 2 ); |
| 33 | |
| 34 | add_filter( 'request', array( $this, 'orderbyDownloads' ) ); |
| 35 | add_filter( 'manage_edit-wpdmpro_sortable_columns', array( $this, 'sortableDownloads' ) ); |
| 36 | |
| 37 | add_action( 'restrict_manage_posts', array( $this, 'categoryFilter' ) ); |
| 38 | add_filter( 'parse_query', array( $this, 'filterByCategory' ) ); |
| 39 | |
| 40 | add_filter( 'display_post_states', array( $this, 'postStates' ), 10, 2 ); |
| 41 | |
| 42 | add_filter( 'bulk_actions-edit-wpdmpro', array( $this, 'bulkActions' ) ); |
| 43 | add_filter( 'handle_bulk_actions-edit-wpdmpro', array( $this, 'handleBulkActions' ), 10, 3 ); |
| 44 | add_action( 'admin_notices', array( $this, 'bulkActionNotices' ) ); |
| 45 | |
| 46 | add_filter( 'post_row_actions', array( $this, 'rowActions' ), 10, 2 ); |
| 47 | |
| 48 | add_action( 'admin_footer', array( $this, 'footerScripts' ) ); |
| 49 | |
| 50 | add_action( "admin_init", [ $this, 'duplicate' ] ); |
| 51 | |
| 52 | } |
| 53 | |
| 54 | function savePackage( $post ) { |
| 55 | if ( ! current_user_can( 'edit_post', $post ) || ! current_user_can( 'upload_files', $post ) ) { |
| 56 | return; |
| 57 | } |
| 58 | if ( get_post_type() != 'wpdmpro' || ! isset( $_POST['file'] ) ) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | $cdata = get_post_custom( $post ); |
| 63 | $donot_delete_meta = array( '__wpdm_favs', '__wpdm_masterkey' ); |
| 64 | foreach ( $cdata as $k => $v ) { |
| 65 | $tk = str_replace( "__wpdm_", "", $k ); |
| 66 | if ( ! isset( $_POST['file'][ $tk ] ) && $tk !== $k && ! in_array( $k, $donot_delete_meta ) ) { |
| 67 | delete_post_meta( $post, $k ); |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |
| 72 | if(isset($_POST['file']['zipped_file'])) { unset($_POST['file']['zipped_file']); } |
| 73 | if(isset($_POST['file']['masterkey'])) { unset($_POST['file']['masterkey']); } |
| 74 | |
| 75 | foreach ( $_POST['file'] as $meta_key => $meta_value ) { |
| 76 | $key_name = "__wpdm_" . $meta_key; |
| 77 | if ( $meta_key == 'package_size' && (double) $meta_value == 0 ) { |
| 78 | $meta_value = ""; |
| 79 | } |
| 80 | if ( $meta_key == 'password' ) { |
| 81 | //don't alter/sanitize password |
| 82 | } |
| 83 | else if ( $meta_key == 'files' ) { |
| 84 | foreach ( $meta_value as &$value ) { |
| 85 | $value = wpdm_escs( $value ); |
| 86 | if ( ! __::is_url( $value ) ) { |
| 87 | if ( WPDM()->fileSystem->isBlocked( $value ) ) { |
| 88 | $value = ''; |
| 89 | } |
| 90 | $abspath = WPDM()->fileSystem->locateFile( $value ); |
| 91 | if ( ! WPDM()->fileSystem->allowedPath( $abspath ) ) { |
| 92 | $value = ''; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | $meta_value = array_unique( $meta_value ); |
| 97 | } else if ( $meta_key == 'terms_conditions' ) { |
| 98 | $meta_value = __::sanitize_var( $meta_value, 'kses' ); |
| 99 | } else if ( $meta_key == 'changelog' ) { |
| 100 | if ( is_array( $meta_value ) ) { |
| 101 | foreach ( $meta_value as &$entry ) { |
| 102 | if ( is_array( $entry ) ) { |
| 103 | $entry['id'] = sanitize_text_field( $entry['id'] ); |
| 104 | $entry['version'] = sanitize_text_field( $entry['version'] ); |
| 105 | $entry['date'] = sanitize_text_field( $entry['date'] ); |
| 106 | $entry['changes'] = wp_kses_post( $entry['changes'] ); |
| 107 | $entry['timestamp'] = absint( $entry['timestamp'] ); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } else { |
| 112 | $meta_value = is_array( $meta_value ) ? wpdm_sanitize_array( $meta_value, 'txt' ) : htmlspecialchars( $meta_value ); |
| 113 | } |
| 114 | update_post_meta( $post, $key_name, $meta_value ); |
| 115 | } |
| 116 | |
| 117 | $masterKey = Crypt::encrypt( [ 'id' => $post, 'time' => time() ] ); |
| 118 | if ( get_post_meta( $post, '__wpdm_masterkey', true ) == '' ) { |
| 119 | update_post_meta( $post, '__wpdm_masterkey', $masterKey ); |
| 120 | } |
| 121 | |
| 122 | if ( isset( $_POST['reset_key'] ) && $_POST['reset_key'] == 1 ) { |
| 123 | update_post_meta( $post, '__wpdm_masterkey', $masterKey ); |
| 124 | } |
| 125 | |
| 126 | if ( isset( $_REQUEST['reset_udl'] ) ) { |
| 127 | WPDM()->downloadHistory->resetUserDownloadCount( $post, 'all' ); |
| 128 | } |
| 129 | do_action( 'wpdm_admin_update_package', $post, $_POST['file'] ); |
| 130 | } |
| 131 | |
| 132 | function duplicate() { |
| 133 | if ( wpdm_query_var( 'wpdm_duplicate', 'int' ) > 0 && get_post_type( wpdm_query_var( 'wpdm_duplicate' ) ) === 'wpdmpro' ) { |
| 134 | if ( ! current_user_can( 'edit_posts' ) || ! wp_verify_nonce( wpdm_query_var( '__copynonce' ), NONCE_KEY ) ) { |
| 135 | wp_die( esc_attr__( 'You are not authorized!', 'download-manager' ) ); |
| 136 | } |
| 137 | Package::copy( wpdm_query_var( 'wpdm_duplicate', 'int' ) ); |
| 138 | wp_redirect( "edit.php?post_type=wpdmpro" ); |
| 139 | die(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | |
| 144 | function uploadFile() { |
| 145 | check_ajax_referer( NONCE_KEY ); |
| 146 | if ( ! current_user_can( 'upload_files' ) ) { |
| 147 | die( '-2' ); |
| 148 | } |
| 149 | |
| 150 | $name = isset( $_FILES['package_file']['name'] ) && ! isset( $_REQUEST["chunks"] ) ? sanitize_file_name( $_FILES['package_file']['name'] ) : wpdm_query_var( 'name', 'txt' ); |
| 151 | |
| 152 | $ext = FileSystem::fileExt( $name ); |
| 153 | |
| 154 | if ( WPDM()->fileSystem->isBlocked( $name, $_FILES['package_file']['tmp_name'] ) ) { |
| 155 | die( '-3' ); |
| 156 | } |
| 157 | |
| 158 | do_action( "wpdm_before_upload_file", $_FILES['package_file'] ); |
| 159 | |
| 160 | @set_time_limit( 0 ); |
| 161 | |
| 162 | if ( ! file_exists( UPLOAD_DIR ) ) { |
| 163 | WPDM()->createDir(); |
| 164 | } |
| 165 | |
| 166 | $filename = $name; |
| 167 | |
| 168 | if ( (int)get_option( '__wpdm_sanitize_filename', 0 ) === 1 ) { |
| 169 | $filename = sanitize_file_name( $filename ); |
| 170 | } else { |
| 171 | $filename = str_replace( [ "/", "\\" ], "_", $filename ); |
| 172 | } |
| 173 | |
| 174 | if ( file_exists( UPLOAD_DIR . $filename ) && ! isset( $_REQUEST["chunks"] ) ) { |
| 175 | $filename = time() . 'wpdm_' . $filename; |
| 176 | } |
| 177 | |
| 178 | |
| 179 | if ( isset( $_REQUEST["chunks"] ) ) { |
| 180 | $this->chunkUploadFile( UPLOAD_DIR . $filename ); |
| 181 | } else { |
| 182 | |
| 183 | $isValidMimeType = FileSystem::validateUploadMimeType($_FILES['package_file']['tmp_name'], $name); |
| 184 | |
| 185 | if(!$isValidMimeType) { |
| 186 | die("|||<div class='alert alert-danger'>".sprintf(__('Upload blocked. The file type is invalid—the file extension does not match the actual content type.', 'download-manager'), '<strong>".UPLOAD_DIR."</strong>')."</div>|||"); |
| 187 | } |
| 188 | |
| 189 | $moved = move_uploaded_file( $_FILES['package_file']['tmp_name'], UPLOAD_DIR . $filename ); |
| 190 | if(!$moved) wpdmdd($_FILES); |
| 191 | //die("|||<div class='alert alert-danger'>Failed to move file in upload dir <strong>".UPLOAD_DIR."</strong>. Please check dir permission or contact server support.|||</div>"); |
| 192 | do_action( "wpdm_after_upload_file", UPLOAD_DIR . $filename ); |
| 193 | } |
| 194 | |
| 195 | //$filename = apply_filters("wpdm_after_upload_file", $filename, UPLOAD_DIR); |
| 196 | |
| 197 | echo "|||" . $filename . "|||"; |
| 198 | exit; |
| 199 | } |
| 200 | |
| 201 | |
| 202 | function chunkUploadFile( $destFilePath ) { |
| 203 | |
| 204 | if ( $destFilePath === '' ) { |
| 205 | return; |
| 206 | } |
| 207 | $chunk = isset( $_REQUEST["chunk"] ) ? intval( $_REQUEST["chunk"] ) : 0; |
| 208 | $chunks = isset( $_REQUEST["chunks"] ) ? intval( $_REQUEST["chunks"] ) : 0; |
| 209 | $out = @fopen( "{$destFilePath}.part", $chunk == 0 ? "wb" : "ab" ); |
| 210 | |
| 211 | if ( $out ) { |
| 212 | // Read binary input stream and append it to temp file |
| 213 | $in = @fopen( $_FILES['package_file']['tmp_name'], "rb" ); |
| 214 | |
| 215 | if ( $in ) { |
| 216 | while ( $buff = fread( $in, 4096 ) ) { |
| 217 | fwrite( $out, $buff ); |
| 218 | } |
| 219 | } else { |
| 220 | die( '-3' ); |
| 221 | } |
| 222 | |
| 223 | @fclose( $in ); |
| 224 | @fclose( $out ); |
| 225 | |
| 226 | @unlink( $_FILES['package_file']['tmp_name'] ); |
| 227 | } else { |
| 228 | die( '-3' . $destFilePath ); |
| 229 | } |
| 230 | |
| 231 | if ( ! $chunks || $chunk == $chunks - 1 ) { |
| 232 | |
| 233 | $isValidMimeType = FileSystem::validateUploadMimeType("{$destFilePath}.part", basename($destFilePath)); |
| 234 | if(!$isValidMimeType) { |
| 235 | @unlink( $destFilePath . ".part" ); |
| 236 | die("|||<div class='alert alert-danger'>".sprintf(__('Upload blocked. The file type is invalid—the file extension does not match the actual content type.', 'download-manager'), '<strong>".UPLOAD_DIR."</strong>')."</div>|||"); |
| 237 | } |
| 238 | |
| 239 | // Strip the temp .part suffix off |
| 240 | rename( "{$destFilePath}.part", $destFilePath ); |
| 241 | do_action( "wpdm_after_upload_file", $destFilePath ); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | |
| 246 | function columnsTH( $defaults ) { |
| 247 | if ( get_post_type() != 'wpdmpro' ) { |
| 248 | return $defaults; |
| 249 | } |
| 250 | $img['image'] = "<span class='wpdm-th-icon ttip' style='font-size: 0.8em'><i style='font-size: 80%' class='far fa-image'></i></span>"; |
| 251 | __::array_splice_assoc( $defaults, 1, 0, $img ); |
| 252 | $otf['download_count'] = "<span class='wpdm-th-icon ttip' title='" . esc_attr__( 'Downloads', 'download-manager' ) . "' style='font-size: 0.8em'><i style='font-size: 80%' class='fas fa-arrow-down'></i></span>"; |
| 253 | $otf['view_count'] = "<span class='wpdm-th-icon ttip' title='" . esc_attr__( 'Views', 'download-manager' ) . "' style='font-size: 0.8em'><i style='font-size: 80%' class='far fa-eye'></i></span>"; |
| 254 | $otf['wpdmembed'] = esc_attr__( 'Shortcode', 'download-manager' ); |
| 255 | __::array_splice_assoc( $defaults, 3, 0, $otf ); |
| 256 | |
| 257 | return $defaults; |
| 258 | } |
| 259 | |
| 260 | |
| 261 | function columnsTD( $column_name, $post_ID ) { |
| 262 | if ( get_post_type() != 'wpdmpro' ) { |
| 263 | return; |
| 264 | } |
| 265 | if ( $column_name == 'download_count' ) { |
| 266 | |
| 267 | echo current_user_can( WPDM_ADMIN_CAP ) || get_the_author_meta( 'ID' ) === get_current_user_id() ? (int) get_post_meta( $post_ID, '__wpdm_download_count', true ) : '—'; |
| 268 | |
| 269 | } |
| 270 | if ( $column_name == 'view_count' ) { |
| 271 | |
| 272 | echo current_user_can( WPDM_ADMIN_CAP ) || get_the_author_meta( 'ID' ) === get_current_user_id() ? (int) get_post_meta( $post_ID, '__wpdm_view_count', true ) : '—'; |
| 273 | |
| 274 | } |
| 275 | if ( $column_name == 'wpdmembed' ) { |
| 276 | |
| 277 | echo "<div class='w3eden'><div class='input-group short-code-wpdm'><input readonly=readonly class='form-control bg-white' onclick='this.select();' value=\"[wpdm_package id='$post_ID']\" id='sci{$post_ID}' /><div class='input-group-btn'><button type='button' onclick=\"WPDM.copy('sci{$post_ID}')\" class='btn btn-secondary'><i class='fa fa-copy'></i></button></div></div></div>"; |
| 278 | //echo "<div class='w3eden'><button type='button' href='#' data-toggle='modal' data-target='#embModal' data-pid='{$post_ID}' class='btn btn-secondary btn-embed'><i class='fa fa-bars'></i></button></div>"; |
| 279 | |
| 280 | } |
| 281 | if ( $column_name == 'image' ) { |
| 282 | if ( has_post_thumbnail( $post_ID ) ) { |
| 283 | echo get_the_post_thumbnail( $post_ID, 'thumbnail', array( 'class' => 'img60px' ) ); |
| 284 | } else { |
| 285 | $icon = get_post_meta( $post_ID, '__wpdm_icon', true ); |
| 286 | if ( $icon != '' ) { |
| 287 | $icon = esc_url($icon); |
| 288 | echo "<img src='$icon' class='img60px' alt='Icon' />"; |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | |
| 295 | function orderbyDownloads( $vars ) { |
| 296 | |
| 297 | if ( isset( $vars['orderby'] ) && 'download_count' == $vars['orderby'] ) { |
| 298 | $vars = array_merge( $vars, array( |
| 299 | 'meta_key' => '__wpdm_download_count', |
| 300 | 'orderby' => 'meta_value_num' |
| 301 | ) ); |
| 302 | } |
| 303 | |
| 304 | if ( isset( $vars['orderby'] ) && 'view_count' == $vars['orderby'] ) { |
| 305 | $vars = array_merge( $vars, array( |
| 306 | 'meta_key' => '__wpdm_view_count', |
| 307 | 'orderby' => 'meta_value_num' |
| 308 | ) ); |
| 309 | } |
| 310 | |
| 311 | return $vars; |
| 312 | } |
| 313 | |
| 314 | function sortableDownloads( $columns ) { |
| 315 | |
| 316 | if ( get_post_type() != 'wpdmpro' ) { |
| 317 | return $columns; |
| 318 | } |
| 319 | |
| 320 | $columns['download_count'] = 'download_count'; |
| 321 | $columns['view_count'] = 'view_count'; |
| 322 | |
| 323 | return $columns; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /** |
| 328 | * Render a category filter dropdown above the package list table. |
| 329 | * |
| 330 | * @return void |
| 331 | */ |
| 332 | function categoryFilter() { |
| 333 | global $typenow; |
| 334 | if ( $typenow !== 'wpdmpro' ) { |
| 335 | return; |
| 336 | } |
| 337 | $taxonomy = 'wpdmcategory'; |
| 338 | wp_dropdown_categories( array( |
| 339 | 'show_option_all' => esc_attr__( 'All Categories', 'download-manager' ), |
| 340 | 'taxonomy' => $taxonomy, |
| 341 | 'name' => $taxonomy, |
| 342 | 'value_field' => 'slug', |
| 343 | 'selected' => wpdm_query_var( $taxonomy, 'txt' ), |
| 344 | 'hierarchical' => true, |
| 345 | 'depth' => 5, |
| 346 | 'orderby' => 'name', |
| 347 | 'show_count' => false, |
| 348 | 'hide_empty' => false, |
| 349 | 'class' => 'postform', |
| 350 | ) ); |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Drop the "All Categories" placeholder (value 0) so it doesn't filter to an empty list. |
| 355 | * |
| 356 | * @param \WP_Query $query |
| 357 | * |
| 358 | * @return void |
| 359 | */ |
| 360 | function filterByCategory( $query ) { |
| 361 | global $pagenow; |
| 362 | if ( ! is_admin() || $pagenow !== 'edit.php' ) { |
| 363 | return; |
| 364 | } |
| 365 | $qv = &$query->query_vars; |
| 366 | if ( isset( $qv['post_type'] ) && $qv['post_type'] === 'wpdmpro' |
| 367 | && isset( $qv['wpdmcategory'] ) && ( $qv['wpdmcategory'] === '0' || $qv['wpdmcategory'] === 0 ) ) { |
| 368 | unset( $qv['wpdmcategory'] ); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Inline "needs attention" / state badges next to a package title in the list. |
| 374 | * |
| 375 | * @param array $states |
| 376 | * @param \WP_Post $post |
| 377 | * |
| 378 | * @return array |
| 379 | */ |
| 380 | function postStates( $states, $post ) { |
| 381 | if ( ! is_object( $post ) || $post->post_type !== 'wpdmpro' || ! current_user_can( WPDM_ADMIN_CAP ) ) { |
| 382 | return $states; |
| 383 | } |
| 384 | if ( ! WPDM()->package->hasAttachment( $post->ID ) ) { |
| 385 | $states['wpdm_nofile'] = esc_html__( 'No file attached', 'download-manager' ); |
| 386 | } |
| 387 | $password_protected = (bool) WPDM()->package->isPasswordProtected( $post->ID ); |
| 388 | if ( $password_protected ) { |
| 389 | $states['wpdm_password'] = esc_html__( 'Password', 'download-manager' ); |
| 390 | } |
| 391 | if ( ! $password_protected && WPDM()->package->isLocked( $post->ID ) ) { |
| 392 | $states['wpdm_locked'] = esc_html__( 'Locked', 'download-manager' ); |
| 393 | } |
| 394 | |
| 395 | return $states; |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Add bulk actions: Duplicate & Reset download count. |
| 400 | * |
| 401 | * @param array $actions |
| 402 | * |
| 403 | * @return array |
| 404 | */ |
| 405 | function bulkActions( $actions ) { |
| 406 | if ( current_user_can( WPDM_ADMIN_CAP ) ) { |
| 407 | $actions['wpdm_duplicate'] = esc_attr__( 'Duplicate', 'download-manager' ); |
| 408 | $actions['wpdm_reset_dlc'] = esc_attr__( 'Reset Download Count', 'download-manager' ); |
| 409 | } |
| 410 | |
| 411 | return $actions; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Process the custom bulk actions. Nonce is verified by WP core before this fires. |
| 416 | * |
| 417 | * @param string $redirect_url |
| 418 | * @param string $action |
| 419 | * @param int[] $post_ids |
| 420 | * |
| 421 | * @return string |
| 422 | */ |
| 423 | function handleBulkActions( $redirect_url, $action, $post_ids ) { |
| 424 | if ( ! current_user_can( WPDM_ADMIN_CAP ) ) { |
| 425 | return $redirect_url; |
| 426 | } |
| 427 | |
| 428 | if ( $action === 'wpdm_duplicate' ) { |
| 429 | $count = 0; |
| 430 | foreach ( (array) $post_ids as $id ) { |
| 431 | if ( get_post_type( $id ) === 'wpdmpro' ) { |
| 432 | Package::copy( (int) $id ); |
| 433 | $count ++; |
| 434 | } |
| 435 | } |
| 436 | $redirect_url = add_query_arg( 'wpdm_bulk_duplicated', $count, $redirect_url ); |
| 437 | } elseif ( $action === 'wpdm_reset_dlc' ) { |
| 438 | $count = 0; |
| 439 | foreach ( (array) $post_ids as $id ) { |
| 440 | if ( get_post_type( $id ) === 'wpdmpro' ) { |
| 441 | update_post_meta( (int) $id, '__wpdm_download_count', 0 ); |
| 442 | $count ++; |
| 443 | } |
| 444 | } |
| 445 | $redirect_url = add_query_arg( 'wpdm_bulk_dlc_reset', $count, $redirect_url ); |
| 446 | } |
| 447 | |
| 448 | return $redirect_url; |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * Confirmation notices after a custom bulk action runs. |
| 453 | * |
| 454 | * @return void |
| 455 | */ |
| 456 | function bulkActionNotices() { |
| 457 | global $pagenow, $typenow; |
| 458 | if ( $pagenow !== 'edit.php' || $typenow !== 'wpdmpro' ) { |
| 459 | return; |
| 460 | } |
| 461 | if ( isset( $_REQUEST['wpdm_bulk_duplicated'] ) ) { |
| 462 | $n = (int) $_REQUEST['wpdm_bulk_duplicated']; |
| 463 | printf( |
| 464 | '<div class="notice notice-success is-dismissible"><p>' . esc_html( _n( '%d package duplicated.', '%d packages duplicated.', $n, 'download-manager' ) ) . '</p></div>', |
| 465 | $n |
| 466 | ); |
| 467 | } |
| 468 | if ( isset( $_REQUEST['wpdm_bulk_dlc_reset'] ) ) { |
| 469 | $n = (int) $_REQUEST['wpdm_bulk_dlc_reset']; |
| 470 | printf( |
| 471 | '<div class="notice notice-success is-dismissible"><p>' . esc_html( _n( 'Download count reset for %d package.', 'Download count reset for %d packages.', $n, 'download-manager' ) ) . '</p></div>', |
| 472 | $n |
| 473 | ); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | |
| 478 | function rowActions( $actions, $post ) { |
| 479 | if ( $post->post_type == 'wpdmpro' && current_user_can( WPDM_ADMIN_CAP ) ) { |
| 480 | $actions['duplicate'] = '<a title="' . __( "Duplicate", "download-manager" ) . '" href="' . admin_url( "/?wpdm_duplicate={$post->ID}&__copynonce=" . wp_create_nonce( NONCE_KEY ) ) . '" class="wpdm_duplicate w3eden">' . esc_attr__( 'Duplicate', 'download-manager' ) . '</a>'; |
| 481 | $actions['view_stats'] = '<a title="' . __( "Stats", "download-manager" ) . '" href="edit.php?post_type=wpdmpro&page=wpdm-stats&pid=' . $post->ID . '" class="view_stats w3eden"><i class="fas fa-chart-pie color-blue"></i></a>'; |
| 482 | if ( $post->post_status == 'publish' ) { |
| 483 | $actions['download_link'] = '<a title="' . __( "Master Download URL", "download-manager" ) . '" href="#" class="gdl_action w3eden" data-mdlu="' . WPDM()->package->getMasterDownloadURL( $post->ID ) . '" data-pid="' . $post->ID . '"><i class="far fa-arrow-alt-circle-down color-purple"></i></a>'; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | return $actions; |
| 488 | } |
| 489 | |
| 490 | |
| 491 | function footerScripts() { |
| 492 | global $pagenow; |
| 493 | if ( wpdm_query_var( 'post_type' ) === 'wpdmpro' && $pagenow === 'edit.php' ) { |
| 494 | ?> |
| 495 | |
| 496 | <style> |
| 497 | |
| 498 | .w3eden #edlModal .modal-content .modal-header i, |
| 499 | .w3eden #gdluModal .modal-content .modal-header i { |
| 500 | margin-right: 6px; |
| 501 | } |
| 502 | |
| 503 | .w3eden #gdluModal .modal-content .modal-footer, |
| 504 | .w3eden #gdluModal .modal-content .modal-header, |
| 505 | .w3eden #edlModal .modal-content .modal-footer, |
| 506 | .w3eden #edlModal .modal-content .modal-header { |
| 507 | border: 0; |
| 508 | } |
| 509 | </style> |
| 510 | |
| 511 | <div class="w3eden"> |
| 512 | <script type="text/template" id="embModal-tpl"> |
| 513 | <div class="modal-body"> |
| 514 | |
| 515 | <div class="input-group input-group-lg"> |
| 516 | <input type="text" value="[wpdm_package id='{{ID}}']" id="cpsc" readonly="readonly" |
| 517 | class="form-control bg-white" |
| 518 | style="font-family: monospace;font-weight: bold;text-align: center"> |
| 519 | <div class="input-group-btn"> |
| 520 | <button style="padding-left: 30px;padding-right: 30px" |
| 521 | onclick="WPDM.copy('cpsc');" type="button" class="btn btn-secondary"><i |
| 522 | class="fa fa-copy"></i> <?php echo esc_attr__( 'Copy', 'download-manager' ); ?> |
| 523 | </button> |
| 524 | </div> |
| 525 | </div> |
| 526 | <div class="alert alert-info" style="margin-top: 20px"> |
| 527 | <?php echo esc_attr__( 'If you are on Gutenberg Editor or elementor, you may use gutenberg block or elementor add-on for wpdm to embed wpdm packages and categories or generate another available layouts', 'download-manager' ); ?> |
| 528 | </div> |
| 529 | |
| 530 | <div class="panel panel-default card-plain"> |
| 531 | <div class="panel-heading"> |
| 532 | <?php echo esc_attr__( 'Go To Page', 'download-manager' ); ?> |
| 533 | </div> |
| 534 | <div class="panel-body"> |
| 535 | <div class="row"> |
| 536 | <div class="col-md-9"><?php wp_dropdown_pages( [ |
| 537 | 'class' => 'form-control wpdm-custom-select', |
| 538 | 'id' => 'gotopg' |
| 539 | ] ); ?></div> |
| 540 | <div class="col-md-3"> |
| 541 | <button onclick="location.href='post.php?action=edit&post='+jQuery('#gotopg').val()" |
| 542 | type="button" |
| 543 | class="btn btn-info btn-block"><?php echo esc_attr__( 'Go', 'download-manager' ); ?></button> |
| 544 | </div> |
| 545 | </div> |
| 546 | |
| 547 | </div> |
| 548 | <div class="panel-footer bg-white"> |
| 549 | <a href="post-new.php?post_type=page"><?php echo esc_attr__( 'Create new page', 'download-manager' ); ?></a> |
| 550 | </div> |
| 551 | </div> |
| 552 | |
| 553 | |
| 554 | <?php if ( ! defined( '__WPDM_GB__' ) ) { ?> |
| 555 | <a class="btn btn-block btn-secondary thickbox open-plugin-details-modal" |
| 556 | href="<?php echo admin_url( '/plugin-install.php?tab=plugin-information&plugin=wpdm-gutenberg-blocks&TB_iframe=true&width=600&height=550' ) ?>"><?php echo esc_attr__( 'Install Gutenberg Blocks by WordPress Download Manager', 'download-manager' ); ?></a> |
| 557 | <?php } ?> |
| 558 | <?php if ( ! defined( '__WPDM_ELEMENTOR__' ) ) { ?> |
| 559 | <a class="btn btn-block btn-secondary thickbox open-plugin-details-modal" |
| 560 | style="margin-top: 10px" |
| 561 | href="<?php echo admin_url( '/plugin-install.php?tab=plugin-information&plugin=wpdm-elementor&TB_iframe=true&width=600&height=550' ) ?>"><?php echo esc_attr__( 'Install Download Manager Addons for Elementor', 'download-manager' ); ?></a> |
| 562 | <?php } ?> |
| 563 | <?php if ( ! function_exists( 'LiveForms' ) ) { ?> |
| 564 | <a class="btn btn-block btn-info thickbox open-plugin-details-modal" |
| 565 | style="margin-top: 10px" |
| 566 | href="<?php echo admin_url( '/plugin-install.php?tab=plugin-information&plugin=liveforms&TB_iframe=true&width=600&height=550' ) ?>"><?php echo esc_attr__( 'Install The Best WordPress Contact Form Builder', 'download-manager' ); ?></a> |
| 567 | <?php } ?> |
| 568 | |
| 569 | |
| 570 | </div> |
| 571 | </script> |
| 572 | |
| 573 | <script type="text/template" id="gdluModal-tpl"> |
| 574 | <div class="modal-body"> |
| 575 | |
| 576 | |
| 577 | <div class="panel panel-default"> |
| 578 | <div class="panel-heading"> |
| 579 | <div class="pull-right"><a id="mdlx" href="#" class="btn btn-xs btn-primary"><i |
| 580 | class="fas fa-arrow-alt-circle-down"></i> <?php _e( 'Download', "download-manager" ); ?> |
| 581 | </a></div> |
| 582 | <?php _e( "Master Download Link:", "download-manager" ); ?> |
| 583 | </div> |
| 584 | <div class="panel-body"> |
| 585 | <div class="input-group"> |
| 586 | <input readonly="readonly" onclick="this.select()" |
| 587 | type="text" class="form-control color-purple" |
| 588 | style="background: #fdfdfd;min-height: 34px;text-align: center;font-family: monospace;font-weight: bold;font-size: 10px;" |
| 589 | id="mdl"/> |
| 590 | <div class="input-group-btn"> |
| 591 | <button type="button" onclick="WPDM.copy('mdl')" class="btn btn-secondary"><i class="fa fa-copy"></i> <?php echo esc_attr__( 'Copy', 'download-manager' ); ?></button> |
| 592 | </div> |
| 593 | </div> |
| 594 | </div> |
| 595 | </div> |
| 596 | |
| 597 | <div class="panel panel-default ttip" style="opacity: 0.3" |
| 598 | title="Available with the pro version only"> |
| 599 | <div class="panel-heading">Generate Temporary Download Link</div> |
| 600 | <div class="panel-body"> |
| 601 | |
| 602 | <div class="row"> |
| 603 | <div class="col-md-3"> |
| 604 | <label>Usage Limit:</label> |
| 605 | <input disabled="disabled" min="1" class="form-control" id="ulimit" |
| 606 | type="number" |
| 607 | placeholder="<?php echo __( "Count", "download-manager" ) ?>" |
| 608 | value="3"> |
| 609 | </div> |
| 610 | <div class="col-md-5"> |
| 611 | <label>Expire After:</label> |
| 612 | <div class="input-group"> |
| 613 | <input disabled="disabled" id="exmisd" min="0.5" step="0.5" |
| 614 | class="form-control" |
| 615 | type="number" value="600" |
| 616 | style="width: 50%;display: inline-block;"> |
| 617 | <select disabled="disabled" id="expire_multiply" |
| 618 | class="form-control wpdm-custom-select" |
| 619 | style="min-width: 50%;max-width: 50% !important;display: inline-block;margin-left: -1px"> |
| 620 | <option value="60">Mins</option> |
| 621 | <option value="3600">Hours</option> |
| 622 | <option value="86400">Days</option> |
| 623 | </select> |
| 624 | </div> |
| 625 | </div> |
| 626 | |
| 627 | <div class="col-md-4"> |
| 628 | <label> </label><br/> |
| 629 | <button disabled="disabled" class="btn btn-info btn-block" |
| 630 | style="height: 34px" type="button">Generate |
| 631 | </button> |
| 632 | </div> |
| 633 | </div> |
| 634 | |
| 635 | </div> |
| 636 | <div class="panel-footer"> |
| 637 | <div class="input-group"> |
| 638 | <div class="input-group-addon"><?php echo __( "Direct download:", "download-manager" ); ?></div> |
| 639 | <input type="text" id="tmpgdl" value="" class="form-control color-green" |
| 640 | readonly="readonly" onclick="this.select()" |
| 641 | style="background: #fdfdfd;font-size: 10px;text-align: center;font-family: monospace;font-weight: bold;" |
| 642 | placeholder="Click Generate Button"> |
| 643 | </div> |
| 644 | </div> |
| 645 | <div class="panel-footer"> |
| 646 | <div class="input-group"> |
| 647 | <div class="input-group-addon"><?php echo __( "Download page:", "download-manager" ); ?></div> |
| 648 | <input type="text" id="tmpgdlp" value="" class="form-control color-green" |
| 649 | readonly="readonly" onclick="this.select()" |
| 650 | style="background: #fdfdfd;font-size: 10px;text-align: center;font-family: monospace;font-weight: bold;" |
| 651 | placeholder="Click Generate Button"> |
| 652 | </div> |
| 653 | </div> |
| 654 | </div> |
| 655 | |
| 656 | |
| 657 | </div> |
| 658 | </script> |
| 659 | |
| 660 | </div> |
| 661 | <script> |
| 662 | jQuery(function ($) { |
| 663 | |
| 664 | |
| 665 | var tdlpid; |
| 666 | $('body').on('click', '.gdl_action', function () { |
| 667 | tdlpid = $(this).attr('data-pid'); |
| 668 | var mdlu = $(this).attr('data-mdlu'); |
| 669 | WPDM.dialog.show({ |
| 670 | title: '<?php echo esc_js(__( "Generate Download Link", "download-manager" )); ?>', |
| 671 | content: document.getElementById('gdluModal-tpl').innerHTML, |
| 672 | size: 'md', icon: false |
| 673 | }); |
| 674 | $('#mdl').val(mdlu); |
| 675 | $('#mdlx').attr('href', mdlu); |
| 676 | $('#tmpgdl').val(''); |
| 677 | $('#tmpgdlp').val(''); |
| 678 | }); |
| 679 | |
| 680 | $('body').on('click', '.btn-embed', function () { |
| 681 | var pid = $(this).data('pid'); |
| 682 | WPDM.dialog.show({ |
| 683 | title: '<?php echo esc_js(__( "Embed Package", "download-manager" )); ?>', |
| 684 | content: document.getElementById('embModal-tpl').innerHTML, |
| 685 | size: 'md', icon: false |
| 686 | }); |
| 687 | $('#cpsc').val("[wpdm_package id='" + pid + "']"); |
| 688 | }); |
| 689 | |
| 690 | |
| 691 | }); |
| 692 | </script> |
| 693 | |
| 694 | <?php |
| 695 | } |
| 696 | |
| 697 | if ( $pagenow === 'themes.php' || $pagenow === 'theme-install.php' ) { |
| 698 | if ( ! file_exists( ABSPATH . '/wp-content/themes/attire/' ) ) { |
| 699 | ?> |
| 700 | <script> |
| 701 | jQuery(function ($) { |
| 702 | $('.page-title-action').after('<a href="<?php echo admin_url( '/theme-install.php?search=attire' ); ?>" class="hide-if-no-js page-title-action" style="border: 1px solid #0f9cdd;background: #13aef6;color: #ffffff;">Suggested Theme</a>'); |
| 703 | }); |
| 704 | </script> |
| 705 | <?php |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | } |
| 710 | |
| 711 | |
| 712 | } |
| 713 |