/**
 * parse and output postpack buy button
 *
 * @since 2.0
 *
 * @param int $postpack_id
 * @return string $html
 */
function mgm_parse_postpack_template($postpack_id)
{
    global $post;
    // logged in
    if (is_user_logged_in()) {
        // return
        return mgm_get_postpack_template($postpack_id);
    }
    // guest token - issue #1396
    if (isset($_GET['guest_token'])) {
        $pack_purchased = false;
        // list of posts
        if ($postpack_posts = mgm_get_postpack_posts($postpack_id)) {
            // init string
            $post_string = '<ul>';
            // loop
            foreach ($postpack_posts as $i => $pack_post) {
                // check if user has purchased
                $access = mgm_user_has_purchased_post($pack_post->post_id, NULL, strip_tags($_GET['guest_token']));
                // set
                if ($access) {
                    // get post
                    $post = get_post($pack_post->post_id);
                    $post_url = get_permalink($post->ID) . '?guest_token=' . strip_tags($_GET['guest_token']);
                    // append
                    $post_string .= sprintf('<li><a href="%s">%s</a></li>', $post_url, $post->post_title);
                    $pack_purchased = true;
                }
            }
            // end
            $post_string .= '</ul>';
        }
        if ($pack_purchased) {
            return $post_string;
        }
    }
    // show links
    // login url
    $login_url = $post->ID > 0 ? mgm_get_custom_url('login', false, array('redirect_to' => get_permalink($post->ID))) : '';
    // template
    $template = mgm_get_template('private_text_template', array(), 'templates');
    // message
    $message = mgm_get_template('private_text_purchasable_pack_login', array(), 'messages');
    //issue #863
    $message = str_replace('[purchase_options]', '', $message);
    $message = __($message, 'mgm');
    $message .= '[purchase_options]';
    // message - issue #1396
    $message = mgm_get_content_purchase_options($message, $login_url, $post->ID, $postpack_id);
    // message
    $message = str_replace('[message]', $message, $template);
    // return
    return sprintf('<div class="mgm_private_no_access">%s</div>', $message);
}
/**
 * check purchased post expired
 */
function mgm_is_user_purchased_post_expired($post_id, $user_id = NULL, $guest_token = NULL)
{
    // return
    return mgm_user_has_purchased_post($post_id, $user_id, $guest_token, true);
}