dlm_downloads ) ) { $total = $wpdb->get_results( "SELECT downloads.download_count FROM {$wpdb->dlm_downloads} downloads INNER JOIN {$wpdb->posts} posts ON downloads.download_id = posts.ID WHERE 1=1 AND posts.post_status = 'publish';", ARRAY_A ); $total = array_sum( array_column( $total, 'download_count' ) ); } else { if ( ! DLM_Logging::is_logging_enabled() ) { return esc_html__( 'Logging is not enabled.', 'download-monitor' ); } return esc_html__( 'Log table not present.', 'download-monitor' ); } /** * Filter the total downloads * * @hooked DLM_Backwards_Compatibility::total_downloads_shortcode - 10 * * @param int $total Total downloads */ return apply_filters( 'dlm_shortcode_total_downloads', $total ); } /** * total_files function. * * @access public * @return void */ public function total_files() { $count_posts = wp_count_posts( 'dlm_download' ); return $count_posts->publish; } /** * download function. * * @access public * * @param array $atts * @param string $content * * @return string */ public function download( $atts, $content = '' ) { // enqueue style only on shortcode use wp_enqueue_style( 'dlm-frontend' ); /** * Action to allow the adition of extra scripts and code related to the shortcode * */ do_action( 'dlm_download_shortcode_scripts' ); // extract shortcode atts extract( shortcode_atts( array( 'id' => '', 'autop' => false, 'template' => dlm_get_default_download_template(), 'version_id' => null, 'version' => '', ), $atts ) ); // Make id filterable $id = apply_filters( 'dlm_shortcode_download_id', $id, $atts ); // Check id if ( empty( $id ) ) { return ''; } // Allow third party extensions to hijack shortcode $hijacked_content = apply_filters( 'dlm_shortcode_download_content', '', $id, $atts, $content ); // If there's hijacked content, return it and be done with it if ( '' !== $hijacked_content ) { return $hijacked_content; } // shortcode output $output = ''; // create download object try { /** @var DLM_Download $download */ $download = download_monitor()->service( 'download_repository' ) ->retrieve_single( $id ); // check if version is set if ( ! empty( $version ) ) { $version_id = $download->get_version_id_version_name( $version ); } // check if version ID is set if ( isset( $version_id ) && 0 != $version_id ) { try { $version = download_monitor() ->service( 'version_repository' ) ->retrieve_single( $version_id ); $download->set_version( $version ); } catch ( Exception $e ) { } } // if we have content, wrap in a link only if ( $content ) { $output = '' . $content . ''; } else { // template handler $template_handler = new DLM_Template_Handler(); // buffer ob_start(); // Load template if ( $download ) { $template_handler->get_template_part( 'content-download', $template, '', array( 'dlm_download' => $download ) ); } else { echo esc_html__( 'No download defined', 'download-monitor' ); } // get output $output .= ob_get_clean(); // check if we need to wpautop() if ( 'true' === $autop || true === $autop ) { $output = wpautop( $output ); } } } catch ( Exception $e ) { $output = '[' . __( 'Download not found', 'download-monitor' ) . ']'; } return $output; } /** * download_data function. * * @access public * * @param array $atts * * @return string */ public function download_data( $atts ) { /** * Action to allow the adition of extra scripts and code related to the shortcode * */ do_action( 'dlm_download_data_shortcode_scripts' ); extract( shortcode_atts( array( 'id' => '', 'data' => '', 'version_id' => null, 'version' => '', ), $atts ) ); $id = apply_filters( 'dlm_shortcode_download_id', $id, $atts ); if ( empty( $id ) || empty( $data ) ) { return ''; } try { /** @var DLM_Download $download */ $download = download_monitor()->service( 'download_repository' ) ->retrieve_single( $id ); if ( ! empty( $version ) ) { $version_id = $download->get_version_id_version_name( $version ); } if ( ! empty( $version_id ) ) { try { $version = download_monitor() ->service( 'version_repository' ) ->retrieve_single( $version_id ); $download->set_version( $version ); } catch ( Exception $e ) { } } switch ( $data ) { // File / Version Info case 'filename': return $download->get_version()->get_filename(); case 'filetype': return $download->get_version()->get_filetype(); case 'filesize': return $download->get_version() ->get_filesize_formatted(); case 'md5': return $download->get_version()->get_md5(); case 'sha1': return $download->get_version()->get_sha1(); case 'sha256': return $download->get_version()->get_sha256(); case 'crc32': case 'crc32b': return $download->get_version()->get_crc32b(); case 'version': return $download->get_version()->get_version_number(); // Download Info case 'title': return $download->get_title(); case 'short_description': return wpautop( wptexturize( do_shortcode( $download->get_excerpt() ) ) ); case 'download_link': return $download->get_the_download_link(); case 'download_count': return $download->get_download_count(); case 'post_content': return wpautop( wptexturize( do_shortcode( $download->get_description() ) ) ); case 'post_date': case 'file_date': return date_i18n( get_option( 'date_format' ), $download->get_version()->get_date() ->format( 'U' ) ); case 'author': return $download->get_the_author(); // Images case 'image': return $download->get_image( 'full' ); case 'thumbnail': return $download->get_image( 'thumbnail' ); // Taxonomies case 'tags': $returnstr = ''; $terms = get_the_terms( $id, 'dlm_download_tag' ); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { $terms_names = array(); foreach ( $terms as $term ) { $terms_names[] = $term->name; } $returnstr = implode( ', ', $terms_names ); } return $returnstr; case 'categories': $returnstr = ''; $terms = get_the_terms( $id, 'dlm_download_category' ); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { $terms_names = array(); foreach ( $terms as $term ) { $terms_names[] = $term->name; } $returnstr = implode( ', ', $terms_names ); } return $returnstr; } } catch ( Exception $e ) { return '[' . __( 'Download not found', 'download-monitor' ) . ']'; } } /** * downloads function. * * @access public * * @param mixed $atts * * @return void */ public function downloads( $atts ) { global $dlm_max_num_pages; /** * Action to allow the adition of extra scripts and code related to the shortcode * */ do_action( 'dlm_downloads_shortcode_scripts' ); // enqueue style only on shortcode use wp_enqueue_style( 'dlm-frontend' ); extract( shortcode_atts( array( // Query args 'per_page' => '-1', // -1 = no limit 'orderby' => 'date', // title, rand, ID, none, date, modifed, post__in, download_count 'order' => 'desc', // ASC or DESC 'include' => '', // Comma separate IDS 'exclude' => '', // Comma separate IDS 'offset' => '', 'category' => '', // Comma separate slugs 'category_include_children' => true, // Set to false to not include child categories 'tag' => '', // Comma separate slugs 'exclude_tag' => '', // Comma separate slugs 'featured' => false, // Set to true to only pull featured downloads 'members_only' => false, // Set to true to only pull member downloads // Output args 'template' => dlm_get_default_download_template(), 'loop_start' => '
' . esc_html( $error_text ) . '
'; } } // load no access template $template_handler->get_template_part( 'no-access', '', '', array( 'download' => $download, 'no_access_message' => ( ( $atts['show_message'] ) ? wp_kses_post( get_option( 'dlm_no_access_error', '' ) ) : '' ), ) ); } catch ( Exception $exception ) { // no download with given ID } // set new content $content = ob_get_clean(); session_write_close(); return $content; } } }