/**
 * get payment subscribe page html
 *
 * @param void
 * @return string
 * @since 1.5
 */
function mgm_get_payment_subscribe_page_html()
{
    // attach scripts, returns
    do_action('mgm_attach_scripts');
    // content
    $html = sprintf('<p>%s</p>', __('You are already subscribed or an error occurred. Please contact an administrator for more information.', 'mgm'));
    // get user query string
    $user = mgm_get_user_from_querystring();
    // member
    if (isset($user) && is_object($user)) {
        $member = mgm_get_member($user->ID);
    }
    // action
    $action = mgm_get_var('action', '', true);
    // print
    if (!empty($action) && count(mgm_get_class('membership_types')->membership_types) > 0) {
        // upgrade or complete
        if (in_array($action, array('upgrade', 'complete_payment'))) {
            $html = mgm_get_upgrade_buttons();
            // extend
        } elseif ($action == 'extend') {
            $html = mgm_get_extend_button();
            // extend
        } elseif ($action == 'purchase_another') {
            $html = mgm_get_purchase_another_subscription_button();
            //TODO
            // bad action
        } else {
            $html = sprintf('<p>%s</p>', sprintf(__('Error - Unknown action - "%s", Exiting...', 'mgm'), $action));
        }
    } elseif (isset($member) && is_object($member) && in_array($member->status, array(MGM_STATUS_NULL, MGM_STATUS_EXPIRED, MGM_STATUS_TRIAL_EXPIRED))) {
        $html = mgm_get_subscription_buttons($user, true);
    } elseif (isset($member) && is_object($member) && $member->status == MGM_STATUS_PENDING) {
        $html = sprintf('<p>%s</p>', __('Error - Your subscription status is pending. Please contact an administrator for more information.', 'mgm'));
    }
    // return
    return apply_filters('mgm_payment_subscribe_page_html', $html);
}
/**
 * parse shortcodes
 *
 * @param array @args
 * @param string @content
 * @param string @tag
 * @return string $content
 */
function mgm_shortcode_parse($args, $content, $tag)
{
    // current_user
    $current_user = wp_get_current_user();
    // system
    $system_obj = mgm_get_class('system');
    // issue#: 859
    // add <p> to the beggining and </p> to the end of content
    // as WP pass $content with incomplete p tags
    $content = '<p>' . $content . '</p>';
    // remove any '<p></p> found
    $content = str_replace(array('<p></p>'), '', $content);
    // @todo test with force_balance_tags();
    // tag block
    switch ($tag) {
        case 'private':
            // [private] protected content [/private]
            if (mgm_protect_content() || mgm_post_is_purchasable()) {
                //issue #1687
                if (mgm_content_post_access_delay($args)) {
                    $content = mgm_replace_postdealy_content($content);
                } else {
                    $content = mgm_replace_content_tags($tag, $content, $args);
                }
            }
            break;
        case 'private_or':
            // [private_or#member] protected content [/private_or]
            // [private_or membership_type="member"] protected content [/private_or]
            $membership_type = isset($args['membership_type']) ? $args['membership_type'] : str_replace('#', '', mgm_array_shift($args));
            // match
            if ($membership_type) {
                $content = mgm_replace_content_tags($tag, $content, $membership_type);
            }
            break;
        case 'private_and':
            // [private_and#member] protected content [/private_and]
            // [private_and membership_type="member"] protected content [/private_and]
            $membership_type = isset($args['membership_type']) ? $args['membership_type'] : str_replace('#', '', mgm_array_shift($args));
            // match
            if ($membership_type) {
                $content = mgm_replace_content_tags($tag, $content, $membership_type);
            }
            break;
        case 'payperpost_pack':
            // [payperpost_pack#1] : 1 = pack_id, packs to be created in MGM -> PayPerPost -> Post Packs, use the id here
            // [payperpost_pack id=1] : 1 = pack_id
            $pack_id = isset($args['id']) ? $args['id'] : str_replace('#', '', mgm_array_shift($args));
            // match
            if ($pack_id) {
                $content = mgm_replace_content_tags($tag, $content, $pack_id);
            }
            break;
        case 'payperpost':
            // [payperpost#1] : 1 = post_id
            // [payperpost id=1] : 1 = post_id
            $pack_id = isset($args['id']) ? $args['id'] : str_replace('#', '', mgm_array_shift($args));
            // match
            if ($pack_id) {
                $content = mgm_replace_content_tags($tag, $content, $pack_id);
            }
            break;
        case 'subscription_packs':
            // subscription packs / payment gateways
            $content = mgm_sidebar_register_links($current_user->user_login, true, 'page');
            // @todo test
            break;
        case 'user_unsubscribe':
            // user unsubscribe
            $content = mgm_user_unsubscribe_info(null, $args);
            // view current user
            break;
        case 'user_other_subscriptions':
            // other subscriptions
            $content = mgm_user_other_subscriptions_info();
            break;
        case 'membership_details':
            // user subscription
            $content = mgm_membership_details();
            // view current user
            break;
        case 'user_upgrade':
            // user upgrade membership
            $content = mgm_get_upgrade_buttons($args);
            break;
        case 'user_purchase_another_membership':
            // purchase another subscription
            $content = mgm_get_purchase_another_subscription_button($args);
            break;
        case 'user_subscribe':
        case 'user_register':
            // named
            if ($method = mgm_get_var('method', '', true)) {
                // method
                switch ($method) {
                    case 'login':
                        $content = mgm_user_login_form(false);
                        break;
                    case 'lostpassword':
                        $content = mgm_user_lostpassword_form(false);
                        break;
                    default:
                        if (preg_match('/^payment/', $method)) {
                            $content = mgm_transactions_page($args);
                        }
                        break;
                }
            } else {
                $content = mgm_user_register_form($args);
            }
            break;
        case 'user_profile':
            // user profile
            $content = mgm_user_profile_form(NULL, false, $args);
            // view
            break;
        case 'user_public_profile':
            // user profile
            $content = mgm_user_public_profile($args);
            // view
            break;
        case 'transactions':
            // user payments/transactions
            $content = mgm_transactions_page($args);
            break;
        case 'user_contents_by_membership':
            // user contents by membership level
            $content = mgm_membership_content_page();
            break;
        case 'user_lostpassword':
            // user lost password form
            $content = mgm_user_lostpassword_form(false);
            break;
        case 'user_login':
            // user login form
            $content = mgm_user_login_form(false);
            break;
        case 'user_field':
            // user field
            $content = __('Experimental', 'mgm');
            break;
        case 'membership_contents':
            // membership contents
            $content = mgm_membership_contents();
            // view current user
            break;
        case 'logout_link':
            // custom logout link
            // [logout_link#Logout]
            // [logout_link label="Logout"]
            $label = isset($args['label']) ? $args['label'] : str_replace('#', '', mgm_array_shift($args));
            // match
            $content = mgm_logout_link($label);
            break;
        case 'membership_extend_link':
            //INCOMPLETE
            // membership extend link
            // [membership_extend_link#Extend]
            // [membership_extend_link label="Extend"]
            $label = isset($args['label']) ? $args['label'] : str_replace('#', '', mgm_array_shift($args));
            // match
            $content = mgm_membership_extend_link($label);
            break;
        case 'download_error':
            // content
            $content = isset($_GET['error_code']) ? mgm_download_error($_GET['error_code']) : '';
            break;
        case 'user_payment_history':
            // content
            $content = mgm_user_payment_history();
            // view current user
            break;
        case 'user_list':
            // content
            $content = mgm_generate_member_list($args);
            break;
        case 'user_facebook_login':
            // content
            $content = mgm_generate_facebook_login();
            break;
        case 'user_facebook_registration':
            // content
            $content = mgm_generate_facebook_registration();
            break;
        case 'user_purchased_contents':
            // content
            $content = mgm_generate_purchased_contents();
            break;
        case 'user_purchasable_contents':
            // content
            $content = mgm_generate_purchasable_contents();
            break;
            /*case 'addon':
            			// content
             			$content = mgm_purchase_addons($args);
            		break;*/
        /*case 'addon':
        			// content
         			$content = mgm_purchase_addons($args);
        		break;*/
        default:
            // default, which are not shortcode but content tags
            $args = str_replace('#', '', mgm_array_shift($args));
            // match
            $content = mgm_replace_content_tags($tag, $content, $args);
            break;
    }
    // return
    return $content;
}