function ym_firesale_ppp($button_code, $code, $post_id)
{
    if (ym_post_is_purchasable()) {
        // post cane be bought, continue
        $post_id = get_the_ID();
        // current post data
        $base_price = get_post_meta($post_id, '_ym_post_purchasable_cost', TRUE);
        $fire_original_cost = get_post_meta($post_id, '_ym_fire_original_cost', TRUE);
        $is_currently_firesale = get_post_meta($post_id, '_ym_fire_active', TRUE);
        if ($ym_firesale_id = ym_firesale_exists($post_id, YM_APP_TYPE_POST)) {
            // a fire sale exists for this ppp
            $tier_data = ym_firesale_get_current_tier($ym_firesale_id);
            $tier_data = $tier_data[0];
            // check the post meta is correct
            if (!get_post_meta($post_id, '_ym_fire_original_cost')) {
                // no base cost
                // post is starting to go on firesale
                // store the original cost
                update_post_meta($post_id, '_ym_fire_original_cost', $base_price);
                ym_firesale_log(array('doing' => 'StartingPricingModel', 'postId' => $post_id, 'tierId' => $tier_data->fire_tier_id, 'tierPacket' => $tier_data));
                ym_fire_sale_start($tier_data->fire_id);
            }
            // check cost update if needed
            if ($base_price != $tier_data->fire_price) {
                if ($tier_data) {
                    update_post_meta($post_id, '_ym_post_purchasable_cost', $tier_data->fire_price);
                    update_post_meta($post_id, '_ym_fire_active', TRUE);
                    ym_firesale_log(array('doing' => 'TierChange', 'postId' => $post_id, 'newPrice' => $tier_data->fire_price, 'currentPrice' => $base_price, 'tierId' => $tier_data->fire_tier_id, 'tierPacket' => $tier_data));
                    ym_firesale_tier_log($tier_data->fire_tier_id);
                    ym_fire_tier_start($tier_data->fire_tier_id);
                } else {
                    // no tier
                    update_post_meta($post_id, '_ym_post_purchasable_cost', $fire_original_cost);
                    delete_post_meta($post_id, '_ym_fire_original_cost');
                    update_post_meta($post_id, '_ym_fire_active', false);
                    ym_firesale_log(array('doing' => 'EndPricingModel', 'postId' => $post_id, 'newPrice' => $fire_original_cost, 'currentPrice' => $base_price, 'tierId' => $tier_data->fire_tier_id, 'tierPacket' => $tier_data));
                }
            }
        } else {
            if ($is_currently_firesale == 1) {
                // firesale needs resetting as it has ended
                update_post_meta($post_id, '_ym_post_purchasable_cost', $fire_original_cost);
                delete_post_meta($post_id, '_ym_fire_original_cost');
                update_post_meta($post_id, '_ym_fire_active', false);
                ym_firesale_log(array('doing' => 'EndPricingModel', 'postId' => $post_id, 'newPrice' => $fire_original_cost, 'currentPrice' => $base_price));
            }
        }
    }
    return $button_code;
}
Esempio n. 2
0
function ym_filter_message($message)
{
    global $current_user, $ym_res;
    $logged_in = false;
    if ($current_user->ID > 0) {
        $logged_in = true;
    }
    /*
     *  [[purchase_cost]] = Cost and currency of a purchasable post
     * [[login_register]] = Login or register form
     * [[login_register_links]] = Links for login and register
     * [[login_link]] = Login link only
     * [[register_link]] = Register link only
     * [[account_types]] = A list of membership levels that can see this post/page
     * [[duration]] = number of days that the user will have access for
     * [[buy_now]] = buy now button for single posts
     * [[paypal_button]] = Paypal image button
     * [[this_page]] = This page URL
     * [[p_id]] = This page/post ID
     * [[auto_buy_post]] = When used as a redirect will forward the user to paypal to buy the post they wanted
     */
    $post_id = get_the_ID();
    $currency = $ym_res->currency;
    $duration = get_post_meta($post_id, '_ym_post_purchasable_duration', 1);
    if (!$duration) {
        $duration = __('unlimited', 'ym');
    }
    $cost = get_post_meta($post_id, '_ym_post_purchasable_cost', 1) . ' ' . $currency;
    $login_register_links = !$logged_in ? ym_get_login_register_links() : '';
    $login_link = !$logged_in ? ym_get_login_link() : '';
    $register_link = !$logged_in ? ym_get_register_link() : '';
    $login_form = !$logged_in ? ym_login_form() : '';
    if (!($account_types = str_replace(';', ', ', get_post_meta($post_id, '_ym_account_type', true)))) {
        if (ym_post_is_purchasable($post_id)) {
            $account_types = 'Purchasable Only';
        } else {
            $account_types = 'No access';
        }
    }
    $message = str_replace('[[purchase_cost]]', $cost, $message);
    $message = str_replace('[[login_register]]', $login_form, $message);
    $message = str_replace('[[login_register_links]]', $login_register_links, $message);
    $message = str_replace('[[login_link]]', $login_link, $message);
    $message = str_replace('[[register_link]]', $register_link, $message);
    $message = str_replace('[[account_types]]', $account_types, $message);
    $message = str_replace('[[duration]]', $duration, $message);
    $message = str_replace('[[this_page]]', get_permalink(), $message);
    $message = str_replace('[[p_id]]', get_the_ID(), $message);
    return $message;
}
/**
Return Purchase Expiry Date/status
*/
function ym_post_purchased_expiry($post_id = FALSE)
{
    $return = '';
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (ym_post_is_purchasable($post_id)) {
        global $ym_user;
        $user_id = $ym_user->ID;
        // TODO: Does NOT return the purchase DATE!
        if ($purchase = ym_has_purchased_post($post_id, $user_id)) {
            if ($days = get_post_meta($post_id, '_ym_post_purchasable_duration', true)) {
                $purchased = ym_post_last_purchase($post_id, $user_id);
                $purchased = $purchased->unixtime;
                $expiry_date = $purchased + $days * 86400;
                if (time() > $expiry_date) {
                    $return = sprintf(__('Access Expired on %s', 'ym'), date(YM_DATE, $expiry_date + get_option('gmt_offset') * 3600));
                } else {
                    $return = sprintf(__('Access Expires on %s', 'ym'), date(YM_DATE, $expiry_date + get_option('gmt_offset') * 3600));
                }
            } else {
                //				$return = __('Content does not expire', 'ym');
                $return = '-';
            }
        } else {
            $return = __('User has not Purchased this Content', 'ym');
        }
    } else {
        $return = __('Content is not Purchasable', 'ym');
    }
    return $return;
}