예제 #1
0
function ym_post_replace($matches, $override_message = false)
{
    get_currentuserinfo();
    global $wpdb, $current_user, $ym_res, $ym_sys;
    //returns nothing in the event of an empty string
    if ($matches == '') {
        return '';
    }
    //user has access copes with validation against user level and ppp
    if (ym_user_has_access()) {
        $return = '<span class="ym_private_access">' . $matches . '</span>';
    } else {
        //by this time the user does not have access
        if (!ym_post_is_purchasable()) {
            if ($current_user->ID == 0) {
                $return = $ym_res->msg_header . $ym_res->private_text . $ym_res->msg_footer;
            } else {
                $return = $ym_res->msg_header . ($override_message ? $override_message : $ym_res->no_access) . $ym_res->msg_footer;
            }
        } else {
            $post_id = get_the_ID();
            if ($current_user->ID > 0) {
                $purchase_limit = get_post_meta($post_id, '_ym_post_purchasable_limit', true);
                $purchased = ym_post_purchased_count($post_id);
                if ($purchase_limit && $purchase_limit - $purchased <= 0) {
                    $return = '<div style="margin-bottom:5px;width:100%;">' . $ym_res->msg_header . $ym_res->purchasable_at_limit . $ym_res->msg_footer . '</div>';
                } else {
                    // TODO: refactor/split out
                    $cost = get_post_meta($post_id, '_ym_post_purchasable_cost', 1);
                    if ($cost) {
                        $product_id = get_post_meta($post_id, '_ym_post_purchasable_product_id', 1);
                        $title = get_the_title();
                        $modules = get_option('ym_modules');
                        $return = '<div style="margin-bottom:5px;width:100%;">' . $ym_res->msg_header . $ym_res->private_text_purchasable . $ym_res->msg_footer . '</div>';
                        //'<div style="margin-bottom:5px;width:100%;">' . $res->private_text_purchasable . '</div>';
                        foreach ($modules as $module) {
                            if (in_array($module, array('ym_free'))) {
                                continue;
                            }
                            $obj = new $module();
                            $button = $obj->gen_buy_now_button($cost, $title, true, $product_id);
                            $return .= "<div style='width:100%;'>" . $button . "</div>";
                        }
                    } else {
                        $return = '<div style="margin-bottom:5px;width:100%;">' . $ym_res->msg_header . $ym_res->purchasable_pack_only . $ym_res->msg_footer . '</div>';
                    }
                }
            } else {
                // not logged in
                $return = '<div style="margin-bottom:5px;width:100%;">' . $ym_res->msg_header . $ym_res->login_first_text . $ym_res->msg_footer . '</div>';
            }
        }
        $return = '<div class="ym_private_no_access">' . $return . '</div>';
    }
    $return = ym_filter_message($return);
    return $return;
}
function ym_content_units_sold($args)
{
    $post_id = isset($args['post_id']) ? $args['post_id'] : get_the_ID();
    if (!$post_id) {
        return '';
    }
    return ym_post_purchased_count($post_id);
}