/**
 * Magic Members parse download shortcode tag
 * @package MagicMembers
 * @desc parse download tag embeded in templates, works via wp shortcode api 
 * @param array
 * @return string
 */
function mgm_shortcode_download_parse($args)
{
    global $wpdb;
    //explode values
    $args = explode('#', $args[0]);
    // get system
    $system_obj = mgm_get_class('system');
    // hook
    $hook = $system_obj->get_setting('download_hook', 'download');
    // slug
    $slug = $system_obj->get_setting('download_slug', 'download');
    //link
    $link = '';
    // count
    if (count($args)) {
        //sql
        $sql = "SELECT id, title, filename, post_date, members_only, user_id,code FROM `" . TBL_MGM_DOWNLOAD . "` WHERE id = {$args[1]}";
        // get downloads
        $downloads = $wpdb->get_results($sql);
        // if has downloads
        if ($downloads) {
            // loop
            foreach ($downloads as $download) {
                // download url
                $download_url = mgm_download_url($download, $slug);
                // trim last slash
                $download_url = rtrim($download_url, '/');
                if (isset($args[2])) {
                    switch (trim($args[2])) {
                        case 'size':
                            // Download link with filesize
                            $link = '<a href="' . $download_url . '" title="' . $download->title . '" >' . $download->title . ' - ' . mgm_file_get_size($download->filename) . '</a>';
                            break;
                        case 'image':
                            // image
                            $download_image_button = sprintf('<img src="%s" alt="%s" />', MGM_ASSETS_URL . 'images/download.gif', $download->title);
                            // add filter
                            $download_image_button = apply_filters('mgm_download_image_button', $download_image_button, $download->title);
                            // Image link
                            $link = '<a href="' . $download_url . '" title="' . $download->title . '">' . $download_image_button . '</a>';
                            break;
                        case 'button':
                            // Button link
                            $link = '<input type="button" name="btndownload-' . $download->id . '" onclick="window.location=\'' . $download_url . '\'" title="' . $download->title . '" value="' . __('Download', 'mgm') . '"/>';
                            break;
                        case 'url':
                            // Download url
                            $link = $download_url;
                            break;
                    }
                } else {
                    // Download link
                    $link = '<a href="' . $download_url . '" title="' . $download->title . '" >' . $download->title . '</a>';
                }
            }
        }
    }
    return $link;
}
示例#2
0
" />		
								</div>
							</div>
							
							<div class="row">
								<div class="cell">
									<b><?php 
_e('Protected URL', 'mgm');
?>
:</b>
								</div>
							</div>	
							<div class="row">
								<div class="cell">
									<?php 
echo mgm_download_url($data['download'], $data['download_slug']);
?>
	
								</div>
							</div>				
						</div>		
					</div>	
				</div>
			</div>
			<div class="row">
				<div class="cell width120px">
					<b><?php 
_e('Restrict Access?', 'mgm');
?>
:</b>
				</div>
/**
 * Magic Members parse download tag
 *
 * @package MagicMembers
 * @since 2.5
 * @desc parse download tag embeded in pots/page, works via wp shortcode api 
 * @param string post/page content
 * @return string modified content
 */
function mgm_download_parse($content)
{
    global $wpdb;
    // get system
    $system_obj = mgm_get_class('system');
    // hook
    $hook = $system_obj->get_setting('download_hook', 'download');
    // slug
    $slug = $system_obj->get_setting('download_slug', 'download');
    // match
    if (substr_count($content, "[" . $hook . "#")) {
        // get downloads
        $downloads = $wpdb->get_results('SELECT id, title, filename, post_date, members_only, user_id,code FROM `' . TBL_MGM_DOWNLOAD . '`');
        // if has downloads
        if ($downloads) {
            // init
            $patts = $subs = array();
            // loop
            foreach ($downloads as $download) {
                // download url
                $download_url = mgm_download_url($download, $slug);
                // trim last slash
                $download_url = rtrim($download_url, '/');
                // Download link
                $link = '<a href="' . $download_url . '" title="' . $download->title . '" >' . $download->title . '</a>';
                $patts[] = "[" . $hook . "#" . $download->id . "]";
                $subs[] = $link;
                // image
                $download_image_button = sprintf('<img src="%s" alt="%s" />', MGM_ASSETS_URL . 'images/download.gif', $download->title);
                // add filter
                $download_image_button = apply_filters('mgm_download_image_button', $download_image_button, $download->title);
                // Image link
                $link = '<a href="' . $download_url . '" title="' . $download->title . '">' . $download_image_button . '</a>';
                $patts[] = "[" . $hook . "#" . $download->id . "#image]";
                $subs[] = $link;
                // Button link
                $link = '<input type="button" name="btndownload-' . $download->id . '" onclick="window.location=\'' . $download_url . '\'" title="' . $download->title . '" value="' . __('Download', 'mgm') . '"/>';
                $patts[] = "[" . $hook . "#" . $download->id . "#button]";
                $subs[] = $link;
                // Download link with filesize
                $link = '<a href="' . $download_url . '" title="' . $download->title . '" >' . $download->title . ' - ' . mgm_file_get_size($download->filename) . '</a>';
                $patts[] = "[" . $hook . "#" . $download->id . "#size]";
                $subs[] = $link;
                // Download url only
                $link = $download_url;
                $patts[] = "[" . $hook . "#" . $download->id . "#url]";
                $subs[] = $link;
            }
            // replace
            $content = str_replace($patts, $subs, $content);
        }
    }
    // return
    return $content;
}