function filter_sdm_post_type_content($content) { global $post; if ($post->post_type == "sdm_downloads") { //Handle the content for sdm_downloads type post //$download_id = $post->ID; //$args = array('id' => $download_id, 'fancy' => '1'); //$content = sdm_create_download_shortcode($args); $id = $post->ID; // Check to see if the download link cpt is password protected $get_cpt_object = get_post($id); $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected; // Get item thumbnail $item_download_thumbnail = get_post_meta($id, 'sdm_upload_thumbnail', true); $isset_download_thumbnail = isset($item_download_thumbnail) && !empty($item_download_thumbnail) ? '<img class="sdm_post_thumbnail_image" src="' . $item_download_thumbnail . '" />' : ''; // Get item title $item_title = get_the_title($id); $isset_item_title = isset($item_title) && !empty($item_title) ? $item_title : ''; // Get item description $isset_item_description = sdm_get_item_description_output($id); //$isset_item_description = apply_filters('the_content', $isset_item_description); // See if user color option is selected $main_opts = get_option('sdm_downloads_options'); $color_opt = $main_opts['download_button_color']; $def_color = isset($color_opt) ? str_replace(' ', '', strtolower($color_opt)) : __('green', 'sdm_lang'); //Download counter //$dl_counter = sdm_create_counter_shortcode(array('id'=>$id)); //*** Generate the download now button code *** $button_text_string = __('Download Now!', 'sdm_lang'); $homepage = get_bloginfo('url'); $download_url = $homepage . '/?smd_process_download=1&download_id=' . $id; $download_button_code = '<a href="' . $download_url . '" class="sdm_download ' . $def_color . '" title="' . $isset_item_title . '">' . $button_text_string . '</a>'; if ($cpt_is_password !== 'no') { //This is a password protected download so replace the download now button with password requirement $download_button_code = sdm_get_password_entry_form($id); } $db_count = sdm_get_download_count_for_post($id); $string = $db_count == '1' ? __('Download', 'sdm_lang') : __('Downloads', 'sdm_lang'); $download_count_string = '<span class="sdm_post_count_number">' . $db_count . '</span><span class="sdm_post_count_string"> ' . $string . '</span>'; //TODO - make this display better with a new design $content = '<div class="sdm_post_item">'; $content .= '<div class="sdm_post_item_top">'; $content .= '<div class="sdm_post_item_top_left">'; $content .= '<div class="sdm_post_thumbnail">' . $isset_download_thumbnail . '</div>'; $content .= '</div>'; //end .sdm_post_item_top_left $content .= '<div class="sdm_post_item_top_right">'; $content .= '<div class="sdm_post_title">' . $isset_item_title . '</div>'; $content .= '<div class="sdm_post_download_count">' . $download_count_string . '</div>'; $content .= '<div class="sdm_post_description">' . $isset_item_description . '</div>'; $content .= '<div class="sdm_post_download_section"><div class="sdm_download_link">' . $download_button_code . '</div></div>'; //$content .= '<div class="sdm_post_meta_section"></div>';//TODO - Show post meta (category and tags) $content .= '</div>'; //end .sdm_post_item_top_right $content .= '</div>'; //end of .sdm_download_item_top $content .= '<div style="clear:both;"></div>'; $content .= '</div>'; //end .sdm_post_item return $content; } return $content; }
function sdm_handle_category_shortcode($args) { extract(shortcode_atts(array('category_slug' => '', 'category_id' => '', 'fancy' => '0', 'button_text' => '', 'new_window' => '', 'orderby' => 'post_date', 'order' => 'DESC', 'pagination' => ''), $args)); // Define vars $field = ''; $terms = ''; // If category slug and category id are empty.. return error if (empty($category_slug) && empty($category_id)) { return '<p style="color: red;">' . __('Error! You must enter a category slug OR a category id with this shortcode. Refer to the documentation for usage instructions.', 'simple-download-monitor') . '</p>'; } else { if (!empty($category_slug) && !empty($category_id)) { return '<p style="color: red;">' . __('Error! Please enter a category slug OR id; not both.', 'simple-download-monitor') . '</p>'; } else { if (!empty($category_slug) && empty($category_id)) { $field = 'slug'; $terms = $category_slug; } else { if (!empty($category_id) && empty($category_slug)) { $field = 'term_id'; $terms = $category_id; } } } } // For pagination $paged = get_query_var('paged') ? absint(get_query_var('paged')) : 1; if (isset($args['pagination'])) { if (!is_numeric($args['pagination'])) { return '<p style="color: red;">' . __('Error! You must enter a numeric number for the "pagination" parameter of the shortcode. Refer to the usage documentation.', 'simple-download-monitor') . '</p>'; } $posts_per_page = $args['pagination']; } else { $posts_per_page = 9999; } // Query cpt's based on arguments above $get_posts = get_posts(array('post_type' => 'sdm_downloads', 'show_posts' => -1, 'posts_per_page' => $posts_per_page, 'tax_query' => array(array('taxonomy' => 'sdm_categories', 'field' => $field, 'terms' => $terms)), 'orderby' => $orderby, 'order' => $order, 'paged' => $paged)); // If no cpt's are found if (!$get_posts) { return '<p style="color: red;">' . __('There are no download items matching this category criteria.', 'simple-download-monitor') . '</p>'; } else { $output = ''; // Setup download location $homepage = get_bloginfo('url'); // See if user color option is selected $main_opts = get_option('sdm_downloads_options'); $color_opt = $main_opts['download_button_color']; $def_color = isset($color_opt) ? str_replace(' ', '', strtolower($color_opt)) : __('green', 'simple-download-monitor'); $window_target = ''; if (!empty($new_window)) { $window_target = 'target="_blank"'; } if (empty($button_text)) { //Use the default text for the button $button_text_string = __('Download Now!', 'simple-download-monitor'); } else { //Use the custom text $button_text_string = $button_text; } // Iterate cpt's foreach ($get_posts as $item) { // Set download location $id = $item->ID; // get each cpt ID $download_url = $homepage . '/?smd_process_download=1&download_id=' . $id; // Get each cpt title $item_title = get_the_title($id); $isset_item_title = isset($item_title) && !empty($item_title) ? $item_title : ''; // Get CPT thumbnail (for fancy option) $item_download_thumbnail = get_post_meta($id, 'sdm_upload_thumbnail', true); $isset_download_thumbnail = isset($item_download_thumbnail) && !empty($item_download_thumbnail) ? '<img class="sdm_download_thumbnail_image" src="' . $item_download_thumbnail . '" />' : ''; // Get item description (for fancy option) $isset_item_description = sdm_get_item_description_output($id); // Setup download button code $download_button_code = '<a href="' . $download_url . '" class="sdm_download ' . $def_color . '" title="' . $isset_item_title . '" ' . $window_target . '>' . $button_text_string . '</a>'; // Generate download buttons if ($fancy == '0') { $output .= '<div class="sdm_download_link">' . $download_button_code . '</div><br />'; } } // End foreach //Fancy 1 and onwards handles the loop inside the template function if ($fancy == '1') { include_once 'includes/templates/fancy1/sdm-fancy-1.php'; $output .= sdm_generate_fancy1_category_display_output($get_posts, $args); } else { if ($fancy == '2') { include_once 'includes/templates/fancy2/sdm-fancy-2.php'; $output .= sdm_generate_fancy2_category_display_output($get_posts, $args); } } // Pagination related if (isset($args['pagination'])) { $posts_per_page = $args['pagination']; $count_sdm_posts = wp_count_posts('sdm_downloads'); $published_sdm_posts = $count_sdm_posts->publish; $total_pages = ceil($published_sdm_posts / $posts_per_page); $big = 999999999; // Need an unlikely integer $pagination = paginate_links(array('base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 'format' => '', 'add_args' => '', 'current' => max(1, get_query_var('paged')), 'total' => $total_pages, 'prev_text' => '←', 'next_text' => '→')); $output .= '<div class="sdm_pagination">' . $pagination . '</div>'; } // Return results return apply_filters('sdm_category_download_items_shortcode_output', $output, $args, $get_posts); } // End else iterate cpt's }
function sdm_generate_fancy1_display_output($args) { //Get the download ID $id = $args['id']; if (!is_numeric($id)) { return '<div class="sdm_error_msg">Error! The shortcode is missing the ID parameter. Please refer to the documentation to learn the shortcode usage.</div>'; } // See if user color option is selected $main_opts = get_option('sdm_downloads_options'); $color_opt = $main_opts['download_button_color']; $def_color = isset($color_opt) ? str_replace(' ', '', strtolower($color_opt)) : __('green', 'simple-download-monitor'); //See if new window parameter is seet $window_target = ''; if (isset($args['new_window']) && $args['new_window'] == '1') { $window_target = 'target="_blank"'; } //Get the download button text $button_text = isset($args['button_text']) ? $args['button_text'] : ''; if (empty($button_text)) { //Use the default text for the button $button_text_string = __('Download Now!', 'simple-download-monitor'); } else { //Use the custom text $button_text_string = $button_text; } // Get permalink $permalink = get_permalink($id); // Get CPT thumbnail $item_download_thumbnail = get_post_meta($id, 'sdm_upload_thumbnail', true); $isset_download_thumbnail = isset($item_download_thumbnail) && !empty($item_download_thumbnail) ? '<img class="sdm_download_thumbnail_image" src="' . $item_download_thumbnail . '" />' : ''; // Get CPT title $item_title = get_the_title($id); $isset_item_title = isset($item_title) && !empty($item_title) ? $item_title : ''; // Get CPT description $isset_item_description = sdm_get_item_description_output($id); // Get download button $homepage = get_bloginfo('url'); $download_url = $homepage . '/?smd_process_download=1&download_id=' . $id; $download_button_code = '<a href="' . $download_url . '" class="sdm_download ' . $def_color . '" title="' . $isset_item_title . '" ' . $window_target . '>' . $button_text_string . '</a>'; // Check to see if the download link cpt is password protected $get_cpt_object = get_post($id); $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected; if ($cpt_is_password !== 'no') { //This is a password protected download so replace the download now button with password requirement $download_button_code = sdm_get_password_entry_form($id); } $db_count = sdm_get_download_count_for_post($id); $string = $db_count == '1' ? __('Download', 'simple-download-monitor') : __('Downloads', 'simple-download-monitor'); $download_count_string = '<span class="sdm_item_count_number">' . $db_count . '</span><span class="sdm_item_count_string"> ' . $string . '</span>'; $css_class = isset($args['css_class']) ? $args['css_class'] : ''; $output = ''; $output .= '<div class="sdm_download_item ' . $css_class . '">'; $output .= '<div class="sdm_download_item_top">'; $output .= '<div class="sdm_download_thumbnail">' . $isset_download_thumbnail . '</div>'; $output .= '<div class="sdm_download_title">' . $isset_item_title . '</div>'; $output .= '</div>'; //End of .sdm_download_item_top $output .= '<div style="clear:both;"></div>'; $output .= '<div class="sdm_download_description">' . $isset_item_description . '</div>'; $output .= '<div class="sdm_download_link">'; $output .= '<span class="sdm_download_button">' . $download_button_code . '</span>'; $output .= '<span class="sdm_download_item_count">' . $download_count_string . '</span>'; $output .= '</div>'; //end .sdm_download_link $output .= '</div>'; //end .sdm_download_item return $output; }
function sdm_generate_fancy2_display_output($args) { //Get the download ID $id = $args['id']; if (!is_numeric($id)) { return '<div class="sdm_error_msg">Error! The shortcode is missing the ID parameter. Please refer to the documentation to learn the shortcode usage.</div>'; } //See if new window parameter is seet $window_target = ''; if (isset($args['new_window']) && $args['new_window'] == '1') { $window_target = 'target="_blank"'; } //Get the download button text $button_text = isset($args['button_text']) ? $args['button_text'] : ''; if (empty($button_text)) { //Use the default text for the button $button_text_string = __('Download Now!', 'sdm_lang'); } else { //Use the custom text $button_text_string = $button_text; } $homepage = get_bloginfo('url'); $download_url = $homepage . '/?smd_process_download=1&download_id=' . $id; $download_button_code = '<a href="' . $download_url . '" class="sdm_fancy2_download" ' . $window_target . '>' . $button_text_string . '</a>'; // Check to see if the download link cpt is password protected $get_cpt_object = get_post($id); $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected; if ($cpt_is_password !== 'no') { //This is a password protected download so replace the download now button with password requirement $download_button_code = sdm_get_password_entry_form($id); } // Get item permalink $permalink = get_permalink($id); // Get item thumbnail $item_download_thumbnail = get_post_meta($id, 'sdm_upload_thumbnail', true); $isset_download_thumbnail = isset($item_download_thumbnail) && !empty($item_download_thumbnail) ? '<img class="sdm_fancy2_thumb_image" src="' . $item_download_thumbnail . '" />' : ''; // Get item title $item_title = get_the_title($id); $isset_item_title = isset($item_title) && !empty($item_title) ? $item_title : ''; // Get item description $isset_item_description = sdm_get_item_description_output($id); $css_class = isset($args['css_class']) ? $args['css_class'] : ''; $output = ''; $output .= '<div class="sdm_fancy2_item ' . $css_class . '">'; $output .= '<div class="sdm_fancy2_wrapper">'; $output .= '<div class="sdm_fancy2_download_item_top">'; $output .= '<div class="sdm_fancy2_download_thumbnail">' . $isset_download_thumbnail . '</div>'; $output .= '</div>'; //End of .sdm_download_item_top $output .= '<div class="sdm_fancy2_download_title">' . $isset_item_title . '</div>'; $output .= '<div class="sdm_fancy2_download_link">' . $download_button_code . '</div>'; $output .= '</div>'; //end .sdm_fancy2_item $output .= '</div>'; //end .sdm_fancy2_wrapper return $output; }