コード例 #1
0
/**
 * Filter custom column content on the edit media table.
 *
 * @since 0.1
 */
function sell_media_payment_content($column, $post_id)
{
    switch ($column) {
        case "id":
            $html = '<a href="' . site_url() . '/wp-admin/post.php?post=' . $post_id . '&action=edit">';
            $html .= $post_id;
            $html .= '</a>';
            echo $html;
            break;
        case "products":
            $products = Sell_Media()->payments->get_products($post_id);
            if ($products) {
                foreach ($products as $product) {
                    $type = !empty($product['type']) ? ' (' . $product['type'] . ') ' : '';
                    echo $product['name'] . $type . '<br />';
                }
            }
            break;
        case "customer":
            echo Sell_Media()->payments->get_buyer_name($post_id);
            break;
        case "total":
            echo sell_media_get_currency_symbol() . number_format(Sell_Media()->payments->get_meta_key($post_id, 'total'), 2, '.', '');
            break;
        default:
            break;
    }
}
コード例 #2
0
ファイル: admin-items.php プロジェクト: aceherbert/Sell-Media
/**
 * Echoes transaction sales, shown in admin
 *
 * @since 0.1
 * @return string
 */
function sell_media_sales_stats()
{
    global $post_id;
    $stats_array = maybe_unserialize(get_post_meta($post_id, 'sell_media_sales_stats', true));
    if ($stats_array) {
        $i = 0;
        $count = count($stats_array);
        foreach ($stats_array as $license_id => $stats) {
            $term_obj = get_term($license_id, 'licenses');
            $i++;
            if ($i == $count) {
                $last_class = 'misc-pub-section-last';
            } else {
                $last_class = null;
            }
            ?>
            <div class="misc-pub-section <?php 
            echo $last_class;
            ?>
"><?php 
            echo $term_obj->name;
            ?>
 <?php 
            echo $stats['count'];
            ?>
 <strong><?php 
            echo sell_media_get_currency_symbol() . $stats['total'];
            ?>
</strong></div>
        <?php 
        }
    } else {
        _e('No sales so far.', 'sell_media');
    }
}
コード例 #3
0
 /**
  * Determine the price for a single item based on the product_id and size_id
  *
  * @param (int)$product_id
  * @param (int)$price_id
  *
  * @return price on success false on failure
  */
 public function get_price($product_id = null, $attachment_id = null, $price_id = null, $formatted = false, $taxonomy = 'price-group')
 {
     $final_price = false;
     // Use custom price of item
     $original_price = get_post_meta($product_id, 'sell_media_price', true);
     if (!empty($original_price) && !empty($price_id) && $price_id == 'original') {
         $final_price = $original_price;
     } elseif (!empty($price_id) && wp_attachment_is_image($attachment_id) && $price_id != 'original') {
         foreach ($this->get_prices($product_id, $taxonomy) as $price) {
             if ($price_id == $price['id']) {
                 $final_price = $price['price'];
             }
         }
     } else {
         $final_price = $this->settings->default_price;
     }
     $final_price = sprintf('%0.2f', $final_price);
     $final_price = $formatted ? sell_media_get_currency_symbol() . $final_price : $final_price;
     return $final_price;
 }
コード例 #4
0
ファイル: shortcodes.php プロジェクト: rickalday/Sell-Media
/**
 * Displays all collections.
 * Adds the 'sell_media_list_all_collections' short code to the editor. [sell_media_list_all_collections]
 *
 * @since 1.5.3
 */
function sell_media_list_all_collections_shortcode($atts)
{
    extract(shortcode_atts(array('details' => 'false', 'thumbs' => 'true'), $atts));
    if ('false' == $thumbs) {
        $html = null;
        $html .= '<div class="sell-media-collections-shortcode">';
        $taxonomy = 'collection';
        $term_ids = array();
        foreach (get_terms($taxonomy) as $term_obj) {
            $password = sell_media_get_term_meta($term_obj->term_id, 'collection_password', true);
            if ($password) {
                $term_ids[] = $term_obj->term_id;
            }
        }
        $args = array('orderby' => 'name', 'hide_empty' => true, 'parent' => 0, 'exclude' => $term_ids);
        $terms = get_terms($taxonomy, $args);
        if (empty($terms)) {
            return;
        }
        $html .= '<ul class="sell-media-collections-shortcode-list">';
        foreach ($terms as $term) {
            $html .= '<li class="sell-media-collections-shortcode-list-item">';
            $html .= '<a href="' . get_term_link($term->slug, $taxonomy) . '" class="sell-media-collections-shortcode-list-item-link">' . $term->name . '</a>';
            $html .= '</li>';
        }
        $html .= '</ul>';
        $html .= '</div>';
        return $html;
    } else {
        $html = null;
        $html .= '<div class="sell-media-collections-shortcode sell-media">';
        $html .= '<div class="sell-media-grid-container">';
        $taxonomy = 'collection';
        $term_ids = array();
        foreach (get_terms($taxonomy) as $term_obj) {
            $password = sell_media_get_term_meta($term_obj->term_id, 'collection_password', true);
            if ($password) {
                $term_ids[] = $term_obj->term_id;
            }
        }
        $args = array('orderby' => 'name', 'hide_empty' => true, 'parent' => 0, 'exclude' => $term_ids);
        $terms = get_terms($taxonomy, $args);
        if (empty($terms)) {
            return;
        }
        foreach ($terms as $term) {
            $args = array('post_status' => 'publish', 'taxonomy' => 'collection', 'field' => 'slug', 'term' => $term->slug, 'tax_query' => array(array('taxonomy' => 'collection', 'field' => 'id', 'terms' => $term_ids, 'operator' => 'NOT IN')));
            $posts = new WP_Query($args);
            $post_count = $posts->found_posts;
            if ($post_count != 0) {
                $html .= '<div class="sell-media-grid third">';
                $html .= '<div class="item-inner sell-media-collection">';
                $args = array('posts_per_page' => 1, 'taxonomy' => 'collection', 'field' => 'slug', 'term' => $term->slug);
                $posts = new WP_Query($args);
                foreach ($posts->posts as $post) {
                    $html .= '<a href="' . get_term_link($term->slug, $taxonomy) . '" class="collection">';
                    $collection_attachment_id = sell_media_get_term_meta($term->term_id, 'collection_icon_id', true);
                    $html .= sell_media_item_icon($post->ID, apply_filters('sell_media_thumbnail', 'medium', false), false);
                    if ('true' == $details) {
                        $settings = sell_media_get_plugin_options();
                        $html .= '<div class="item-overlay">';
                        $html .= '<div class="collection-details">';
                        $html .= '<span class="collection-count">';
                        $html .= '<span class="count">' . $post_count . '</span>' . __(' images in ', 'sell_media') . '<span class="collection">' . $term->name . '</span>' . __(' collection', 'sell_media');
                        $html .= '</span>';
                        $html .= '<span class="collection-price">';
                        $html .= __('Starting at ', 'sell_media') . '<span class="price">' . sell_media_get_currency_symbol() . $settings->default_price . '</span>';
                        $html .= '</span>';
                        $html .= '</div>';
                        $html .= '</div>';
                        $html .= '<h3>' . $term->name . '</h3>';
                    }
                    $html .= '</a>';
                }
                $html .= '</div>';
                $html .= '</div>';
            }
        }
        $html .= '</div>';
        $html .= '</div>';
        return $html;
    }
}
コード例 #5
0
ファイル: cart.php プロジェクト: rickalday/Sell-Media
                    </fieldset>
                <?php 
}
?>
            </div>

            <?php 
do_action('sell_media_cart_below_licenses');
?>

            <div class="total-container group">
                <strong><?php 
_e('Total', 'sell_media');
?>
:</strong> <span class="price-container"><?php 
echo sell_media_get_currency_symbol();
?>
<span id="total" class="item_price" data-price=<?php 
echo $price;
?>
><?php 
echo $price;
?>
</span></span>
            </div>

            <div class="button-container group">
                <p id="sell-media-add-to-cart"><button class="item_add sell-media-button" <?php 
if (!$is_package && $has_price_group) {
    echo 'disabled';
}
コード例 #6
0
 /**
  * Used to build out an HTML table for a single payment containing all items for that payment
  *
  * @param $post_id (int) The post_id for a post of post type "sell_media_payment"
  *
  * @return $html (string) An html table containing the item, size, price, qty, and other usefulness
  */
 public function payment_table($post_id = null)
 {
     $html = null;
     $html .= '<table class="wp-list-table widefat" cellspacing="0">';
     $html .= '<thead>
             <tr>
                 <th scope="col">' . __('Item', 'sell_media') . '</th>
                 <th>' . __('Size', 'sell_media') . '</th>
                 <th>' . __('Price', 'sell_media') . '</th>
                 <th>' . __('Quantity', 'sell_media') . '</th>
                 <th>' . __('License', 'sell_media') . '</th>
                 <th>' . apply_filters('sell_media_download_link_label', 'Download Link') . '</th>
             </tr>
         </thead>';
     $html .= '<tbody>';
     $products = $this->get_products($post_id);
     if ($products) {
         foreach ($this->get_products($post_id) as $product) {
             $product['attachment'] = !empty($product['attachment']) ? $product['attachment'] : null;
             $product['size']['name'] = !empty($product['size']['name']) ? $product['size']['name'] : null;
             $product['size']['id'] = !empty($product['size']['id']) ? $product['size']['id'] : null;
             $product['size']['amount'] = !empty($product['size']['amount']) ? $product['size']['amount'] : null;
             $product['license']['name'] = !empty($product['license']['name']) ? $product['license']['name'] : null;
             $image_id = $product['attachment'] ? $product['attachment'] : $product['id'];
             $html .= '<tr class="" valign="top">';
             $html .= '<td class="media-icon">';
             $html .= '<a href="' . get_edit_post_link($product['id']) . '">' . sell_media_item_icon($image_id, 'medium', false) . '</a></td>';
             $html .= '<td>' . $product['size']['name'] . '</td>';
             $html .= '<td>' . sell_media_get_currency_symbol() . $product['size']['amount'] . '</td>';
             $html .= '<td>' . $product['qty'] . '</td>';
             $html .= '<td>' . $product['license']['name'] . '</td>';
             if (!empty($product['type']) && 'print' == $product['type']) {
                 $html .= '<td class="title column-title">Sold a print</td>';
             } else {
                 $html .= '<td class="title column-title"><input type="text" value="' . $this->get_download_link($post_id, $product['id'], $product['attachment'], $product['size']['id']) . '" /></td>';
             }
             $html .= '</tr>';
         }
         // get legacy (pre 1.8) purchase data
     } else {
         $payment_meta = get_post_meta($post_id, '_sell_media_payment_meta');
         if (!$payment_meta) {
             return;
         }
         $products_legacy = maybe_unserialize($payment_meta['products']);
         if ($products_legacy) {
             foreach ($products as $product) {
                 $html .= '<tr class="" valign="top">';
                 $html .= '<td class="media-icon">';
                 $html .= '<a href="' . get_edit_post_link($product['id']) . '">' . sell_media_item_icon($product['id'], 'medium', false) . '</a></td>';
                 $html .= '<td>' . $product['price']['name'] . '</td>';
                 $html .= '<td>' . sell_media_get_currency_symbol() . $product['price']['amount'] . '</td>';
                 $html .= '<td>' . $product['qty'] . '</td>';
                 $html .= '<td>' . $product['license']['name'] . '</td>';
                 $html .= '<td class="title column-title"><input type="text" value="' . $this->get_download_link($post_id, $product['id'], $product['attachment'], $product['size']['id']) . '" /></td>';
                 $html .= '</tr>';
             }
         }
         // foreach
     }
     // if legacy
     $html .= '</tbody>';
     $html .= '</table>';
     return $html;
 }
コード例 #7
0
ファイル: term-meta.php プロジェクト: rickalday/Sell-Media
/**
 * Function for building the slider on Add/Edit License admin page
 *
 * @since 0.1
 */
function sell_media_the_markup_slider($tag)
{
    if (isset($_GET['tag_ID'])) {
        $term_id = $_GET['tag_ID'];
    } else {
        $term_id = null;
    }
    if (sell_media_get_term_meta($term_id, 'markup', true)) {
        $initial_markup = str_replace("%", "", sell_media_get_term_meta($term_id, 'markup', true));
    } else {
        $initial_markup = 0;
    }
    $settings = sell_media_get_plugin_options();
    ?>
    <script>
    jQuery(document).ready(function($){

        if ( ! jQuery().slider )
            return;

        function calc_price( markUp ){

            var price = <?php 
    echo $settings->default_price;
    ?>
;

            if ( markUp == undefined )
                var markUp = <?php 
    print $initial_markup;
    ?>
;

            finalPrice = ( +price + ( +markUp * .01 ) * price );
            finalPrice = finalPrice.toFixed(2);

            return finalPrice;
        }

        $( ".menu-cart-total" ).html( calc_price() );

        $( "#markup_slider" ).slider({
            range: "min",
            value: <?php 
    print $initial_markup;
    ?>
,
            min: 0,
            step: .1,
            max: 1000,
            slide: function( event, ui ) {
                var markUp = ui.value;
                $( ".markup-target" ).val(  markUp + "%" );
                $( ".markup-target" ).html(  markUp + "%" );

                $( ".menu-cart-total" ).html( calc_price( markUp ) );
            }
        });
        $( ".markup-target" ).val( $( "#markup_slider" ).slider( "value" ) + "%" );
    });
    </script>
    <div class="sell_media-slider-container">
        <div id="markup_slider"></div>
        <div class="sell_media-price-container">
            <input name="meta_value[markup]" class="markup-target" type="text" value="<?php 
    echo sell_media_get_term_meta($term_id, 'markup', true);
    ?>
" size="40" />
        </div>
        <p class="description">
            <?php 
    _e('Increase the price of a item if a buyer selects this license by dragging the slider above.', 'sell_media');
    ?>
            <?php 
    if (sell_media_get_term_meta($term_id, 'markup', true)) {
        $default_markup = sell_media_get_term_meta($term_id, 'markup', true);
    } else {
        $default_markup = '0%';
    }
    if ($settings->default_price) {
        $price = sell_media_get_currency_symbol() . $settings->default_price;
    } else {
        $price = __('you have not set a default price', 'sell_media');
    }
    printf(__(' The %1$s of %2$s with %3$s markup is %4$s', 'sell_media'), '<a href="' . admin_url() . 'edit.php?post_type=sell_media_item&page=sell_media_plugin_options&tab=sell_media_general_settings
                ">default item price</a>', '<strong>' . $price . '</strong>', '<strong><span class="markup-target">' . $default_markup . '</span></strong>', '<strong>' . sell_media_get_currency_symbol() . '<span class="menu-cart-total"></span></strong>');
    ?>
        </p>
    </div>
<?php 
}
コード例 #8
0
    public function setting_ui()
    {
        $parent_terms = get_terms($this->taxonomy, array('hide_empty' => false, 'parent' => 0));
        $current_parent = empty($_GET['term_parent']) ? '' : $_GET['term_parent'];
        if (is_wp_error($parent_terms)) {
            return;
        }
        $tmp = array();
        $final = array();
        $final['terms'] = null;
        $count = count($parent_terms);
        $current_term_id = null;
        $current_term = null;
        // Build our menu array
        foreach ($parent_terms as $term) {
            if ($current_parent == $term->term_id) {
                $current_term = $term->name;
                $current_term_id = $term->term_id;
                $link = '<span class="nav-tab nav-tab-active">' . $term->name . '</span>';
            } else {
                $link = '<a href="' . admin_url('edit.php?post_type=sell_media_item&page=sell_media_plugin_options&tab=sell_media_size_settings&term_parent=' . $term->term_id) . '" class="nav-tab" data-term_id="' . $term->term_id . '">' . $term->name . '</a>';
            }
            $tmp[] = array('term_id' => $term->term_id, 'name' => $term->name, 'current_id' => $current_term_id, 'current_term' => $current_term, 'html' => $link);
            $final['menu'] = $tmp;
        }
        if (empty($current_parent) || $current_parent == 'new_term') {
            $final['menu'][] = array('html' => '<span class="nav-tab-active nav-tab menu-add-new"><abbr title="Add menu">+</abbr></span>');
        } else {
            $final['menu'][] = array('html' => '<a href="' . admin_url('edit.php?post_type=sell_media_item&page=sell_media_plugin_options&tab=sell_media_size_settings&term_parent=new_term') . '" class="nav-tab menu-add-new"><abbr title="Add menu">+</abbr></a>');
        }
        // header
        if (empty($current_term_id)) {
            $value = null;
            $data_term_id = null;
            $class = "button-primary sell-media-add-term";
            $link_text = __('Create Price Group', 'sell_media');
            $message = null;
        } else {
            $data_term_id = $current_term_id;
            $class = "submitdelete sell-media-delete-term-group";
            $message = sprintf("%s %s?\n\n%s", __("Are you sure you want to delete the price group:", "sell_media"), $current_term, __("This will delete the price group and ALL its prices associated with it.", "sell_media"));
            $link_text = __('Delete Group', 'sell_media');
        }
        $final['header'] = array('html' => '<input name="price_group[term_name]" type="text" class="regular-text" placeholder="' . __('Enter price group name here', 'sell_media') . '" value="' . $current_term . '" data-term_id="' . $data_term_id . '" data-taxonomy="' . $this->taxonomy . '" />
                <input type="hidden" value="' . $data_term_id . '" name="price_group[term_id]" />
                <a href="#" class="' . $class . '" data-term_id="' . $data_term_id . '" data-message="' . $message . '" data-taxonomy="' . $this->taxonomy . '">' . $link_text . '</a>');
        // build terms array
        $tmp = null;
        $terms_obj = get_terms($this->taxonomy, array('hide_empty' => false, 'child_of' => $current_term_id, 'orderby' => 'id'));
        foreach ($terms_obj as $term) {
            $tmp[] = array_merge((array) $term, array('field' => array('html' => '
                                <input type="text" class="" name="terms_children[' . $term->term_id . '][name]" size="24" value="' . $term->name . '" />
                                <p class="description">' . __('Name (shown to buyer, so be descriptive)', 'sell_media') . '</p>')), array('meta' => array('html' => '
                        <td>
                            <input type="text" class="small-text" name="terms_children[' . $term->term_id . '][width]" value="' . sell_media_get_term_meta($term->term_id, 'width', true) . '">
                            <p class="description">' . __('Max width (pixels)', 'sell_media') . '</p>
                        </td>

                        <td>
                            <input type="text" class="small-text" name="terms_children[' . $term->term_id . '][height]" value="' . sell_media_get_term_meta($term->term_id, 'height', true) . '">
                            <p class="description">' . __('Max Height (pixels)', 'sell_media') . '</p>
                        </td>

                        <td>
                            <input type="text" class="small-text" name="terms_children[' . $term->term_id . '][price]" value="' . sprintf('%0.2f', sell_media_get_term_meta($term->term_id, 'price', true)) . '">
                            <p class="description">' . __('Price', 'sell_media') . ' (' . sell_media_get_currency_symbol() . ')</p>
                        </td>')), array('delete' => array('html' => '<a href="#" class="sell-media-xit sell-media-delete-term" data-taxonomy="' . $this->taxonomy . '" data-term_id="' . $term->term_id . '" data-type="price" data-message="' . sprintf('%s: %s?', __('Are you sure you want to delete the price', 'sell_media'), $term->name) . '">×</a>')));
            $final['terms'] = $tmp;
        }
        $final_additional = apply_filters('sell_media_additional_meta_price_group', $this->taxonomy, $final['terms']);
        if (!empty($final_additional)) {
            $final['terms'] = $final_additional;
        } else {
            $final['terms'] = $tmp;
        }
        if (has_filter('sell_media_additional_meta_price_group')) {
            $final['terms'] = apply_filters('sell_media_additional_meta_price_group', $this->taxonomy, $final['terms']);
        } else {
            $final['terms'] = $tmp;
        }
        // Default terms
        $max = count($final['terms']) < 1 ? 1 : 1;
        $html = null;
        for ($i = 1; $i <= $max; $i++) {
            $html .= '<tr class="sell-media-price-groups-row" data-index="' . $i . '">
                    <td class="name">
                        <input type="text" class="" name="new_child[' . $i . '][name]" size="24" value="">
                        <p class="description">' . __('Name (shown to buyer, so be descriptive)', 'sell_media') . '</p>
                    </td>
                    <td>
                        <input type="hidden" class="sell-media-price-group-parent-id" name="new_child[' . $i . '][parent]" value="' . $current_term_id . '" />
                        <input type="text" class="small-text" name="new_child[' . $i . '][width]" value="">
                        <p class="description">' . __('Max width (pixels)', 'sell_media') . '</p>
                    </td>
                    <td>
                        <input type="text" class="small-text" name="new_child[' . $i . '][height]" value="">
                        <p class="description">' . __('Max height (pixels)', 'sell_media') . '</p>
                    </td>
                    <td>
                        <input type="text" class="small-text" name="new_child[' . $i . '][price]" value="">
                        <p class="description">' . __('Price', 'sell_media') . ' (' . sell_media_get_currency_symbol() . ')</p>
                    </td>
                </tr>';
        }
        $price_copy = apply_filters('sell_media_default_price_copy', __('The sizes listed below determine the maximum dimensions in pixels. Price Groups only apply to images.', 'sell_media'), $this->taxonomy);
        $price_group_copy = apply_filters('sell_media_default_price_group_copy', __('Create a price group to add prices to.', 'sell_media'), $this->taxonomy);
        ?>
        <div id="menu-management-liquid" class="sell-media-price-groups-container">
            <input type="hidden" value="<?php 
        echo $this->taxonomy;
        ?>
" name="taxonomy" id="smtaxonomy" />
            <div id="menu-management">

                <div class="nav-tabs-nav">
                    <div class="nav-tabs-wrapper">
                        <div class="nav-tabs">
                            <?php 
        foreach ($final['menu'] as $menu) {
            ?>
                                <?php 
            echo $menu['html'];
            ?>
                            <?php 
        }
        ?>
                        </div>
                    </div>
                </div>
                <!-- Nav menu -->

                <div class="menu-edit">

                    <!-- Print out the input field w/term name and delete button -->
                    <div id="nav-menu-header">
                        <?php 
        foreach ($final['header'] as $header) {
            ?>
                            <?php 
            echo $header;
            ?>
                        <?php 
        }
        ?>
                    </div>


                    <table class="form-table sell-media-price-groups-table" id="sell-media-<?php 
        echo $this->taxonomy;
        ?>
">
                        <tbody>
                            <tr>
                                <td colspan="4">
                                    <p>
                                        <?php 
        if (isset($_GET['term_parent']) && $_GET['term_parent'] == 'new_term') {
            ?>
                                            <?php 
            echo $price_group_copy;
            ?>
                                        <?php 
        } else {
            ?>
                                            <?php 
            echo $price_copy;
            ?>
                                        <?php 
        }
        ?>
                                    </p>
                                </td>
                            </tr>
                            <?php 
        if (empty($current_term_id)) {
            ?>

                            <?php 
        } else {
            ?>
                                <?php 
            if ($final['terms'] && is_array($final['terms'])) {
                foreach ($final['terms'] as $term) {
                    ?>
                                    <tr>
                                        <td><?php 
                    echo $term['field']['html'];
                    ?>
</td>
                                        <?php 
                    echo $term['meta']['html'];
                    ?>
                                        <td><?php 
                    echo $term['delete']['html'];
                    ?>
</td>
                                    </tr>
                                <?php 
                }
            }
            ?>
                                <?php 
            echo apply_filters('sell_media_default_price_group_children', $html, $this->taxonomy, $current_term_id);
            ?>
                            <?php 
        }
        ?>
                        </tbody>

                        <?php 
        if (!empty($current_term_id)) {
            ?>
                            <tfoot>
                                <tr colspan="4">
                                    <td>
                                        <a href="#" class="button sell-media-price-groups-repeater-add"><?php 
            _e('Add New Price', 'sell_media');
            ?>
</a>
                                    </td>
                                </tr>
                            </tfoot>
                        <?php 
        }
        ?>
                    </table>
                    <div class="nav-menu-footer">
                        <?php 
        if (!empty($current_term)) {
            ?>
                            <a href="#" class="button-primary sell-media-save-term" data-taxonomy="<?php 
            echo $this->taxonomy;
            ?>
"><?php 
            _e('Save Price Group', 'sell_media');
            ?>
</a>
                        <?php 
        }
        ?>
                    </div><!-- /.nav-menu-footer -->
                </div>
            </div><!-- /.menu-edit -->
        </div><!-- /#menu-management -->
    <?php 
    }