/** * Shortcode for zeen101's Leaky Paywall * Prints out the zeen101's Leaky Paywall * * @since CHANGEME */ function do_leaky_paywall_profile($atts) { $settings = get_leaky_paywall_settings(); $mode = 'off' === $settings['test_mode'] ? 'live' : 'test'; $defaults = array(); // Merge defaults with passed atts // Extract (make each array element its own PHP var $args = shortcode_atts($defaults, $atts); extract($args); $results = ''; if (is_user_logged_in()) { $sites = array(''); global $blog_id; if (is_multisite_premium()) { if (!is_main_site($blog_id)) { $sites = array('_all', '_' . $blog_id); } else { $sites = array('_all', '_' . $blog_id, ''); } } $user = wp_get_current_user(); $results .= sprintf(__('<p>Welcome %s, you are currently logged in. <a href="%s">Click here to log out.</a></p>', 'issuem-leaky-paywall'), $user->user_login, wp_logout_url(get_page_link($settings['page_for_login']))); //Your Subscription $results .= '<h2>' . __('Your Subscription', 'issuem-leaky-paywall') . '</h2>'; $results .= apply_filters('leaky_paywall_profile_your_subscription_start', ''); $results .= '<table>'; $results .= '<thead>'; $results .= '<tr>'; $results .= ' <th>' . __('Status', 'issuem-leaky-paywall') . '</th>'; $results .= ' <th>' . __('Type', 'issuem-leaky-paywall') . '</th>'; $results .= ' <th>' . __('Payment Method', 'issuem-leaky-paywall') . '</th>'; $results .= ' <th>' . __('Expiration', 'issuem-leaky-paywall') . '</th>'; $results .= ' <th>' . __('Cancel?', 'issuem-leaky-paywall') . '</th>'; $results .= '</tr>'; $results .= '</thead>'; foreach ($sites as $site) { $status = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status' . $site, true); $level_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_level_id' . $site, true); $level_id = apply_filters('get_leaky_paywall_users_level_id', $level_id, $user, $mode, $site); $level_id = apply_filters('get_leaky_paywall_subscription_level_level_id', $level_id); if (false === $level_id || empty($settings['levels'][$level_id]['label'])) { $level_name = __('Undefined', 'issuem-leaky-paywall'); } else { $level_name = stripcslashes($settings['levels'][$level_id]['label']); } $payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); $expires = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_expires' . $site, true); $expires = apply_filters('do_leaky_paywall_profile_shortcode_expiration_column', $expires, $user, $mode, $site, $level_id); if (empty($expires) || '0000-00-00 00:00:00' === $expires) { $expires = __('Never', 'issuem-leaky-paywall'); } else { $date_format = get_option('date_format'); $expires = mysql2date($date_format, $expires); } $plan = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_plan' . $site, true); if (!empty($plan) && 'Canceled' !== $plan && 'Never' !== $expires) { $expires = sprintf(__('Recurs on %s', 'issuem-leaky-paywall'), $expires); } $paid = leaky_paywall_has_user_paid($user->user_email, $site); if ('subscription' === $paid) { $subscriber_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true); $payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); $cancel = sprintf(__('<a href="%s">cancel</a>', 'issuem-leaky-paywall'), '?cancel&payment_gateway=' . $payment_gateway . '&subscriber_id=' . $subscriber_id); } else { $cancel = ' '; } if (!empty($status) && !empty($level_name) && !empty($payment_gateway) && !empty($expires)) { $results .= '<tbody>'; $results .= ' <td>' . ucfirst($status) . '</td>'; $results .= ' <td>' . $level_name . '</td>'; $results .= ' <td>' . leaky_paywall_translate_payment_gateway_slug_to_name($payment_gateway) . '</td>'; $results .= ' <td>' . $expires . '</td>'; $results .= ' <td>' . $cancel . '</td>'; $results .= '</tbody>'; } } $results .= '</table>'; $results .= apply_filters('leaky_paywall_profile_your_subscription_end', ''); //Your Mobile Devices include_once ABSPATH . 'wp-admin/includes/plugin.php'; if (is_plugin_active('unipress-api/unipress-api.php')) { global $unipress_api; $results .= '<h2>' . __('Your Mobile Devices', 'issuem-leaky-paywall') . '</h2>'; $results .= '<p>' . __('To generate a token for the mobile app, click the "Add New Mobile Device" button below.', 'issuem-leaky-paywall') . '</p>'; $results .= apply_filters('leaky_paywall_profile_your_mobile_devices_start', ''); $results .= $unipress_api->leaky_paywall_subscriber_info_paid_subscriber_end(''); $results .= apply_filters('leaky_paywall_profile_your_mobile_devices_end', ''); } //Your Profile $results .= '<h2>' . __('Your Profile', 'issuem-leaky-paywall') . '</h2>'; if (!empty($_POST['leaky-paywall-profile-nonce'])) { if (wp_verify_nonce($_POST['leaky-paywall-profile-nonce'], 'leaky-paywall-profile')) { try { $userdata = get_userdata($user->ID); $args = array('ID' => $user->ID, 'user_login' => $userdata->user_login, 'display_name' => $userdata->display_name, 'user_email' => $userdata->user_email); if (!empty($_POST['username'])) { $args['user_login'] = $_POST['username']; } if (!empty($_POST['displayname'])) { $args['display_name'] = $_POST['displayname']; } if (!empty($_POST['email'])) { if (is_email($_POST['email'])) { $args['user_email'] = $_POST['email']; } else { throw new Exception(__('Invalid email address.', 'issuem-leaky-paywall')); } } if (!empty($_POST['password1']) && !empty($_POST['password2'])) { if ($_POST['password1'] === $_POST['password2']) { wp_set_password($_POST['password1'], $user->ID); } else { throw new Exception(__('Passwords do not match.', 'issuem-leaky-paywall')); } } $user_id = wp_update_user($args); if (is_wp_error($user_id)) { throw new Exception($user_id->get_error_message()); } else { $user = get_userdata($user_id); //Refresh the user object $results .= '<p class="save">' . __('Profile Changes Saved.', 'issuem-leaky-paywall') . '</p>'; } } catch (Exception $e) { $results .= '<p class="error">' . $e->getMessage() . '</p>'; } } } $results .= apply_filters('leaky_paywall_profile_your_profile_start', ''); $results .= '<form id="leaky-paywall-profile" action="" method="post">'; $results .= '<p>'; $results .= '<label class="leaky-paywall-field-label" for="leaky-paywall-username">' . __('Username', 'issuem-leaky-paywall') . '</label>'; $results .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-username" name="username" value="' . $user->user_login . '" disabled="disabled" readonly="readonly" />'; $results .= '</p>'; $results .= '<p>'; $results .= '<label class="leaky-paywall-field-label" for="leaky-paywall-display-name">' . __('Display Name', 'issuem-leaky-paywall') . '</label>'; $results .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-display-name" name="displayname" value="' . $user->display_name . '" />'; $results .= '</p>'; $results .= '<p>'; $results .= '<label class="leaky-paywall-field-label" for="leaky-paywall-email">' . __('Email', 'issuem-leaky-paywall') . '</label>'; $results .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-email" name="email" value="' . $user->user_email . '" />'; $results .= '</p>'; $results .= '<p>'; $results .= '<label class="leaky-paywall-field-label" for="leaky-paywall-password1">' . __('New Password', 'issuem-leaky-paywall') . '</label>'; $results .= '<input type="password" class="issuem-leaky-paywall-field-input" id="leaky-paywall-password1" name="password1" value="" />'; $results .= '</p>'; $results .= '<p>'; $results .= '<label class="leaky-paywall-field-label" for="leaky-paywall-gift-subscription-password2">' . __('New Password (again)', 'issuem-leaky-paywall') . '</label>'; $results .= '<input type="password" class="issuem-leaky-paywall-field-input" id="leaky-paywall-gift-subscription-password2" name="password2" value="" />'; $results .= '</p>'; $results .= wp_nonce_field('leaky-paywall-profile', 'leaky-paywall-profile-nonce', true, false); $results .= '<p class="submit"><input type="submit" id="submit" class="button button-primary" value="' . __('Update Profile Information', 'issuem-leaky-paywall') . '" /></p>'; $results .= '</form>'; $results .= apply_filters('leaky_paywall_profile_your_profile_end', ''); $results .= '<div class="issuem-leaky-paywall-subscriber-info">'; if (false !== ($expires = leaky_paywall_has_user_paid())) { //Your Payment Information if (!empty($_POST['leaky-paywall-profile-stripe-cc-update-nonce'])) { if (wp_verify_nonce($_POST['leaky-paywall-profile-stripe-cc-update-nonce'], 'leaky-paywall-profile-stripe-cc-update')) { try { $secret_key = 'test' === $mode ? $settings['test_secret_key'] : $settings['live_secret_key']; foreach ($sites as $site) { $subscriber_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true); if (!empty($subscriber_id)) { break; } } $cu = Stripe_Customer::retrieve($subscriber_id); if (!empty($cu)) { if (true === $cu->deleted) { throw new Exception(__('Unable to find valid Stripe customer ID to unsubscribe. Please contact support', 'issuem-leaky-paywall')); } } if (empty($_POST['stripe-cc-number'])) { throw new Exception(__('Credit Card Number Required', 'issuem-leaky-paywall')); } if (empty($_POST['stripe-cc-exp-month'])) { throw new Exception(__('Credit Card Expiration Month Required', 'issuem-leaky-paywall')); } if (empty($_POST['stripe-cc-exp-year'])) { throw new Exception(__('Credit Card Expiration Year Required', 'issuem-leaky-paywall')); } if (empty($_POST['stripe-cc-cvc'])) { throw new Exception(__('Credit Card Security Code (CVC) Required', 'issuem-leaky-paywall')); } if (empty($_POST['stripe-cc-name'])) { throw new Exception(__("Credit Card Cardholder's Name Required", 'issuem-leaky-paywall')); } $subscriptions = $cu->subscriptions->all('limit=1'); foreach ($subscriptions->data as $susbcription) { $sub = $cu->subscriptions->retrieve($susbcription->id); $sub->card = array('number' => $_POST['stripe-cc-number'], 'exp_month' => $_POST['stripe-cc-exp-month'], 'exp_year' => $_POST['stripe-cc-exp-year'], 'cvc' => $_POST['stripe-cc-cvc'], 'name' => $_POST['stripe-cc-name']); $sub->save(); } $results .= '<p>' . __('Your credit card has been successfully updated.', 'issuem-leaky-paywall') . '</p>'; } catch (Exception $e) { $results = '<h1>' . sprintf(__('Error updating Credit Card information: %s', 'issuem-leaky-paywall'), $e->getMessage()) . '</h1>'; } } } $results .= apply_filters('leaky_paywall_profile_your_payment_info_start', ''); $results .= apply_filters('leaky_paywall_subscriber_info_paid_subscriber_start', ''); foreach ($sites as $site) { $payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); $subscriber_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true); $expires = leaky_paywall_has_user_paid($user->user_email, $site); if ('subscription' === $expires) { $payment_form = ''; switch ($payment_gateway) { case 'stripe': $payment_form .= '<h3>' . __('Update Credit Card', 'issuem-leaky-paywall') . '</h3>'; $payment_form .= '<form id="leaky-paywall-update-credit-card" action="" method="post">'; $payment_form .= '<p>'; $payment_form .= '<label class="lp-field-label" for="leaky-paywall-cc-number">' . __('Card Number', 'issuem-leaky-paywall') . '</label>'; $payment_form .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-cc-number" name="stripe-cc-number" value="" placeholder="4242 4242 4242 4242" />'; $payment_form .= '</p>'; $payment_form .= '<p>'; $payment_form .= '<label class="lp-field-label" for="leaky-paywall-cc-expiration">' . __('Expiration Date', 'issuem-leaky-paywall') . '</label>'; $payment_form .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-cc-exp-month" name="stripe-cc-exp-month" value="" placeholder="' . date_i18n('m', strtotime('+1 Month')) . '" />'; $payment_form .= ' / '; $payment_form .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-cc-exp-year" name="stripe-cc-exp-year" value="" placeholder="' . date_i18n('Y', strtotime('+1 Year')) . '" />'; $payment_form .= '</p>'; $payment_form .= '<p>'; $payment_form .= '<label class="lp-field-label" for="leaky-paywall-cc-cvc">' . __('Security Code (CVC)', 'issuem-leaky-paywall') . '</label>'; $payment_form .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-cc-cvc" name="stripe-cc-cvc" value="" placeholder="777" />'; $payment_form .= '</p>'; $payment_form .= '<p>'; $payment_form .= '<label class="lp-field-label" for="leaky-paywall-cc-name">' . __("Cardholder's Name", 'issuem-leaky-paywall') . '</label>'; $payment_form .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-cc-name" name="stripe-cc-name" value="" placeholder="John Doe" />'; $payment_form .= '</p>'; $payment_form .= wp_nonce_field('leaky-paywall-profile-stripe-cc-update', 'leaky-paywall-profile-stripe-cc-update-nonce', true, false); $payment_form .= '<p class="submit"><input type="submit" id="submit" class="button button-primary" value="' . __('Update Credit Card Information', 'issuem-leaky-paywall') . '" /></p>'; $payment_form .= '</form>'; break; case 'paypal-standard': case 'paypal_standard': $paypal_url = 'test' === $mode ? 'https://www.sandbox.paypal.com/' : 'https://www.paypal.com/'; $paypal_email = 'test' === $mode ? $settings['paypal_sand_email'] : $settings['paypal_live_email']; $payment_form .= '<p>' . __("You can update your payment details through PayPal's website.", 'issuem-leaky-paywall') . '</p>'; $payment_form .= '<p><a href="' . $paypal_url . '"><img src="https://www.paypalobjects.com/webstatic/en_US/btn/btn_pponly_142x27.png" border="0"></a></p>'; break; } $results .= '<h2>' . __('Your Payment Information', 'issuem-leaky-paywall') . '</h2>'; $results .= $payment_form; break; //We only want the first match } } } else { $results .= '<h2>' . __('Your Account is Not Currently Active', 'issuem-leaky-paywall') . '</h2>'; $results .= '<p>' . sprintf(__('To reactivate your account, please visit our <a href="%s">Subscription page</a>.', 'issuem-leaky-paywall'), get_page_link($settings['page_for_subscription'])) . '</p>'; } $results .= '</div>'; $results .= apply_filters('leaky_paywall_profile_your_payment_info_end', ''); } else { $results .= do_leaky_paywall_login(array()); } return $results; }
function is_issuem_leaky_subscriber_logged_in() { _deprecated_function(__FUNCTION__, 'CHANGEME', 'leaky_paywall_has_user_paid()'); return leaky_paywall_has_user_paid(); }
function process_requests() { $settings = $this->get_settings(); do_action('leaky_paywall_before_process_requests', $settings); $has_subscriber_paid = leaky_paywall_has_user_paid(); if (isset($_REQUEST['issuem-pdf-download'])) { //Admins or subscribed users can download PDFs if (current_user_can(apply_filters('leaky_paywall_current_user_can_view_all_content', 'manage_options')) || $has_subscriber_paid) { leaky_paywall_server_pdf_download($_REQUEST['issuem-pdf-download']); } else { $output = '<h3>' . __('Unauthorize PDF Download', 'issuem-leaky-paywall') . '</h3>'; $output .= '<p>' . sprintf(__('You must be <a href="%s">logged in</a> with a valid subscription to download Issue PDFs.', 'issuem-leaky-paywall'), get_page_link($settings['page_for_login'])) . '</p>'; $output .= '<a href="' . get_home_url() . '">' . sprintf(__('back to %s', 'issuem-leak-paywall'), $settings['site_name']) . '</a>'; wp_die(apply_filters('leaky_paywall_unauthorized_pdf_download_output', $output)); } } if (is_singular()) { global $blog_id; if (is_multisite_premium()) { $site = '_' . $blog_id; } else { $site = ''; } if (!current_user_can(apply_filters('leaky_paywall_current_user_can_view_all_content', 'manage_options'))) { //Admins can see it all // We don't ever want to block the login, subscription if (!is_page(array($settings['page_for_login'], $settings['page_for_subscription'], $settings['page_for_profile'], $settings['page_for_register']))) { global $post; $post_type_id = ''; $restricted_post_type = ''; $is_restricted = false; $restrictions = leaky_paywall_subscriber_restrictions(); if (empty($restrictions)) { $restrictions = $settings['restrictions']['post_types']; } //default restrictions if (!empty($restrictions)) { foreach ($restrictions as $key => $restriction) { if (is_singular($restriction['post_type'])) { if (0 <= $restriction['allowed_value']) { $post_type_id = $key; $restricted_post_type = $restriction['post_type']; $is_restricted = true; break; } } } } $level_ids = leaky_paywall_subscriber_current_level_ids(); $visibility = get_post_meta($post->ID, '_issuem_leaky_paywall_visibility', true); if (false !== $visibility && !empty($visibility['visibility_type']) && 'default' !== $visibility['visibility_type']) { switch ($visibility['visibility_type']) { // using trim() == false instead of empty() for older versions of php // see note on http://php.net/manual/en/function.empty.php case 'only': $only = array_intersect($level_ids, $visibility['only_visible']); if (empty($only)) { add_filter('the_content', array($this, 'the_content_paywall'), 999); do_action('leaky_paywall_is_restricted_content'); return; } break; case 'always': $always = array_intersect($level_ids, $visibility['always_visible']); if (in_array(-1, $visibility['always_visible']) || !empty($always)) { //-1 = Everyone return; //always visible, don't need process anymore } break; case 'onlyalways': $onlyalways = array_intersect($level_ids, $visibility['only_always_visible']); if (empty($onlyalways)) { add_filter('the_content', array($this, 'the_content_paywall'), 999); do_action('leaky_paywall_is_restricted_content'); return; } else { if (!empty($onlyalways)) { return; //always visible, don't need process anymore } } break; } } $is_restricted = apply_filters('leaky_paywall_filter_is_restricted', $is_restricted, $restrictions, $post); if ($is_restricted) { switch ($settings['cookie_expiration_interval']) { case 'hour': $multiplier = 60 * 60; //seconds in an hour break; case 'day': $multiplier = 60 * 60 * 24; //seconds in a day break; case 'week': $multiplier = 60 * 60 * 24 * 7; //seconds in a week break; case 'month': $multiplier = 60 * 60 * 24 * 7 * 4; //seconds in a month (4 weeks) break; case 'year': $multiplier = 60 * 60 * 24 * 7 * 52; //seconds in a year (52 weeks) break; } $expiration = time() + $settings['cookie_expiration'] * $multiplier; if (!empty($_COOKIE['issuem_lp' . $site])) { $available_content = maybe_unserialize(stripslashes($_COOKIE['issuem_lp' . $site])); } if (empty($available_content[$restricted_post_type])) { $available_content[$restricted_post_type] = array(); } foreach ($available_content[$restricted_post_type] as $key => $restriction) { if (time() > $restriction || 7200 > $restriction) { //this post view has expired //Or it is very old and based on the post ID rather than the expiration time unset($available_content[$restricted_post_type][$key]); } } if (-1 != $restrictions[$post_type_id]['allowed_value']) { //-1 means unlimited if ($restrictions[$post_type_id]['allowed_value'] > count($available_content[$restricted_post_type])) { if (!array_key_exists($post->ID, $available_content[$restricted_post_type])) { $available_content[$restricted_post_type][$post->ID] = $expiration; } } else { if (!array_key_exists($post->ID, $available_content[$restricted_post_type])) { add_filter('the_content', array($this, 'the_content_paywall'), 999); do_action('leaky_paywall_is_restricted_content'); } } } $serialized_available_content = maybe_serialize($available_content); setcookie('issuem_lp' . $site, $serialized_available_content, $expiration, '/'); $_COOKIE['issuem_lp' . $site] = $serialized_available_content; } return; //We don't need to process anything else after this } } } if ($has_subscriber_paid) { if ((!empty($settings['page_for_subscription']) && is_page($settings['page_for_subscription']) || !empty($settings['page_for_profile']) && is_page($settings['page_for_profile'])) && isset($_REQUEST['cancel'])) { wp_die(leaky_paywall_cancellation_confirmation()); } if (!empty($settings['page_for_login']) && is_page($settings['page_for_login'])) { if (!empty($settings['page_for_profile'])) { wp_safe_redirect(get_page_link($settings['page_for_profile'])); } else { if (!empty($settings['page_for_subscription'])) { wp_safe_redirect(get_page_link($settings['page_for_subscription'])); } } } } else { if (!empty($settings['page_for_login']) && is_page($settings['page_for_login']) && !empty($_REQUEST['r'])) { $login_hash = $_REQUEST['r']; if (verify_leaky_paywall_login_hash($login_hash)) { leaky_paywall_attempt_login($login_hash); if (!empty($settings['page_for_profile'])) { wp_safe_redirect(get_page_link($settings['page_for_profile'])); } else { if (!empty($settings['page_for_subscription'])) { wp_safe_redirect(get_page_link($settings['page_for_subscription'])); } } } else { $output = '<h3>' . __('Invalid or Expired Login Link', 'issuem-leaky-paywall') . '</h3>'; $output .= '<p>' . sprintf(__('Sorry, this login link is invalid or has expired. <a href="%s">Try again?</a>', 'issuem-leaky-paywall'), get_page_link($settings['page_for_login'])) . '</p>'; $output .= '<a href="' . get_home_url() . '">' . sprintf(__('back to %s', 'issuem-leak-paywall'), $settings['site_name']) . '</a>'; wp_die(apply_filters('leaky_paywall_invalid_login_link', $output)); } return; //We don't need to process anything else after this } } }
/** * Returns current user's subscription restrictions * * @since 3.0.0 * * @return array subscriber's subscription restrictions */ function leaky_paywall_subscriber_current_level_ids() { $level_ids = array(); if (leaky_paywall_has_user_paid()) { $settings = get_leaky_paywall_settings(); $sites = array(''); if (is_multisite_premium()) { global $blog_id; if (!is_main_site($blog_id)) { $sites = array('_all', '_' . $blog_id); } else { $sites = array('_all', '_' . $blog_id, ''); } } $user = wp_get_current_user(); $mode = 'off' === $settings['test_mode'] ? 'live' : 'test'; foreach ($sites as $site) { $level_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_level_id' . $site, true); $level_id = apply_filters('get_leaky_paywall_users_level_id', $level_id, $user, $mode, $site); $level_id = apply_filters('get_leaky_paywall_subscription_level_level_id', $level_id); $status = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status' . $site, true); if ('active' === $status && is_numeric($level_id)) { $level_ids[] = $level_id; } } } return $level_ids; }