function edit()
 {
     global $wpdb;
     // trim
     array_map('trim', $_POST);
     // extract
     extract($_POST);
     // system
     $system_obj = mgm_get_class('system');
     // save
     if (isset($submit_download)) {
         // response
         $response = array('status' => 'error', 'message' => sprintf(__('Error while updating download <b>%s</b>!', 'mgm'), $title));
         // check duplicate
         if (mgm_is_duplicate(TBL_MGM_DOWNLOAD, array('title'), "id <> '{$id}'")) {
             $response['message'] = sprintf(__('Error while updating download <b>%s</b>, title exists!', 'mgm'), $title);
         } else {
             // set vars
             $members_only = isset($members_only) ? 'Y' : 'N';
             // set vars
             $restrict_acces_ip = isset($restrict_acces_ip) ? 'Y' : 'N';
             // is_s3_torrent
             $is_s3_torrent = isset($is_s3_torrent) ? 'Y' : 'N';
             // filename
             $filename = isset($download_file_new) ? $download_file_new : $direct_url;
             // real name
             $real_filename = isset($download_file_new_realname) ? $download_file_new_realname : basename($filename);
             // filesize
             $filesize = mgm_file_get_size($filename);
             // post vars
             $post_date = date('Y-m-d H:i:s');
             // user
             $current_user = wp_get_current_user();
             // data
             $data = array('title' => $title, 'filename' => $filename, 'real_filename' => $real_filename, 'filesize' => $filesize, 'post_date' => $post_date, 'restrict_acces_ip' => $restrict_acces_ip, 'user_id' => $current_user->ID, 'members_only' => $members_only, 'is_s3_torrent' => $is_s3_torrent);
             // null
             $null_columns = array();
             // download limit
             if (isset($download_limit) && (int) $download_limit > 0) {
                 $data['download_limit'] = (int) $download_limit;
             } else {
                 $null_columns[] = "`download_limit` = NULL ";
             }
             // expire date
             if (isset($expire_dt) && !empty($expire_dt)) {
                 $data['expire_dt'] = mgm_format_inputdate_to_mysql($expire_dt);
             } else {
                 $null_columns[] = "`expire_dt` = NULL ";
             }
             // code
             if (!isset($code) || isset($code) && empty($code)) {
                 $data['code'] = uniqid();
             }
             // update
             if ($wpdb->update(TBL_MGM_DOWNLOAD, $data, array('id' => $id))) {
                 // update null
                 if (count($null_columns) > 0) {
                     // join
                     $set_string = implode(',', $null_columns);
                     // clear old
                     $wpdb->query($wpdb->prepare('UPDATE `' . TBL_MGM_DOWNLOAD . '` SET ' . $set_string . ' WHERE `id` = %d', $id));
                 }
                 // clear old
                 $wpdb->query($wpdb->prepare('DELETE FROM `' . TBL_MGM_DOWNLOAD_POST_ASSOC . '` WHERE `download_id` = %d', $id));
                 // save
                 if (bool_from_yn($members_only)) {
                     if (isset($link_to_post_id)) {
                         // loop
                         foreach ($link_to_post_id as $post_id) {
                             // insert
                             $wpdb->insert(TBL_MGM_DOWNLOAD_POST_ASSOC, array('download_id' => $id, 'post_id' => $post_id));
                         }
                     }
                 }
                 // set message
                 $response['message'] = sprintf(__('Download updated successfully <b>%s</b>', 'mgm'), $title);
                 $response['status'] = 'success';
             } else {
                 $response['message'] = sprintf(__('Error while updating download <b>%s</b> Or nothing updated!', 'mgm'), $title);
             }
         }
         // return response
         echo json_encode($response);
         exit;
     }
     // data
     $data = array();
     // download
     $data['download'] = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . TBL_MGM_DOWNLOAD . "` WHERE id = %d", $id));
     // download_posts
     $data['download_posts'] = mgm_get_download_post_ids($id);
     // get all post types
     $post_types = mgm_get_post_types();
     //get all published posts - issue #1034
     $all_posts = mgm_field_values($wpdb->posts, 'ID', 'SUBSTR(post_title,1, 100) AS post_title', "AND `post_status` ='publish' AND `post_type` IN ({$post_types})", 'post_title');
     //get all scheduled posts
     $scheduled_posts = mgm_field_values($wpdb->posts, 'ID', 'SUBSTR(post_title,1, 100) AS post_title', "AND `post_status` ='future' AND `post_type` IN ({$post_types})", 'post_title');
     foreach ($scheduled_posts as $k => $scheduled_post) {
         $all_posts[$k] = $scheduled_post . '(S)';
     }
     //get all draft posts
     $draft_posts = mgm_field_values($wpdb->posts, 'ID', 'SUBSTR(post_title,1, 100) AS post_title', "AND `post_status` ='draft' AND `post_type` IN ({$post_types})", 'post_title');
     foreach ($draft_posts as $k => $draft_post) {
         $all_posts[$k] = $draft_post . '(D)';
     }
     //sort by post name
     asort($all_posts);
     //all posts
     $data['posts'] = $all_posts;
     // hook
     $data['download_hook'] = $system_obj->get_setting('download_hook', 'download');
     // slug
     $data['download_slug'] = $system_obj->get_setting('download_slug', 'download');
     // load template view
     $this->load->template('downloads/edit', array('data' => $data));
 }
/**
 * 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;
}
示例#3
0
$date_format_short = mgm_get_date_format('date_format_short');
//$path = get_option('siteurl') . '/wp-content/uploads/';
$path = WP_UPLOAD_URL;
// hook
$download_hook = mgm_get_class('system')->get_setting('download_hook', 'download');
// loop
if (count($data['downloads']) > 0) {
    foreach ($data['downloads'] as $download) {
        //// user
        $user = get_userdata($download->user_id);
        // file name
        $filename = $download->real_filename ? $download->real_filename : str_replace($path, '', $download->filename);
        // links
        $filename = end(explode('/', $filename));
        // file size
        $filesize = is_null($download->filesize) || (int) substr(trim($download->filesize), 0, 1) == 0 ? mgm_file_get_size($download->filename) : $download->filesize;
        // expire
        $expire_dt = intval($download->expire_dt) > 0 ? date($date_format_short, strtotime($download->expire_dt)) : __('Never', 'mgm');
        // post
        $post_date = date($wp_date_format, strtotime($download->post_date));
        // format
        $lbl_fmt = '<span class="%s">%s</span>';
        ?>

					<div class="row <?php 
        echo $alt = $alt == '' ? 'alternate' : '';
        ?>
" id="download_row_<?php 
        echo $download->id;
        ?>
">			
/**
 * 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;
}