示例#1
0
 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
         }
     }
 }
示例#2
0
 function leaky_paywall_subscription_options()
 {
     global $blog_id;
     $settings = get_leaky_paywall_settings();
     $current_level_ids = leaky_paywall_subscriber_current_level_ids();
     $results = apply_filters('leaky_paywall_subscription_options', '');
     //If someone wants to completely override this, they can with the above filter
     if (empty($results)) {
         $has_allowed_value = false;
         $results .= '<h2>' . __('Subscription Options', 'issuem-leaky-paywall') . '</h2>';
         $results .= apply_filters('leaky_paywall_subscription_options_header', '');
         if (!empty($settings['levels'])) {
             $results .= apply_filters('leaky_paywall_before_subscription_options', '');
             $results .= '<div class="leaky_paywall_subscription_options">';
             foreach (apply_filters('leaky_paywall_subscription_levels', $settings['levels']) as $level_id => $level) {
                 if (!empty($level['deleted'])) {
                     continue;
                 }
                 if (is_multisite_premium() && !empty($level['site']) && 'all' != $level['site'] && $blog_id != $level['site']) {
                     continue;
                 }
                 $level = apply_filters('leaky_paywall_subscription_options_level', $level, $level_id);
                 $payment_options = '';
                 $allowed_content = '';
                 if (in_array($level_id, $current_level_ids)) {
                     $current_level = 'current-level';
                 } else {
                     $current_level = '';
                 }
                 $results .= '<div id="option-' . $level_id . '" class="leaky_paywall_subscription_option ' . $current_level . '">';
                 $results .= '<h3>' . stripslashes($level['label']) . '</h3>';
                 $results .= '<div class="leaky_paywall_subscription_allowed_content">';
                 foreach ($level['post_types'] as $post_type) {
                     /* @todo: We may need to change the site ID during this process, some sites may have different post types enabled */
                     $post_type_obj = get_post_type_object($post_type['post_type']);
                     if (!empty($post_type_obj)) {
                         if (0 <= $post_type['allowed_value']) {
                             $has_allowed_value = true;
                             $allowed_content .= '<p>' . sprintf(__('Access %s %s*', 'issuem-leaky-paywall'), $post_type['allowed_value'], $post_type_obj->labels->name) . '</p>';
                         } else {
                             $allowed_content .= '<p>' . sprintf(__('Unlimited %s', 'issuem-leaky-paywall'), $post_type_obj->labels->name) . '</p>';
                         }
                     }
                 }
                 $results .= apply_filters('leaky_paywall_subscription_options_allowed_content', $allowed_content, $level_id, $level);
                 $results .= '</div>';
                 $currency = $settings['leaky_paywall_currency'];
                 $currencies = leaky_paywall_supported_currencies();
                 $results .= '<div class="leaky_paywall_subscription_price">';
                 $results .= '<p>';
                 if (!empty($level['price'])) {
                     if (!empty($level['recurring']) && 'on' === $level['recurring'] && apply_filters('leaky_paywall_subscription_options_price_recurring_on', true, $current_level)) {
                         $results .= '<strong>' . sprintf(__('%s%s %s (recurring)', 'issuem-leaky-paywall'), $currencies[$currency]['symbol'], number_format($level['price'], 2), leaky_paywall_human_readable_interval($level['interval_count'], $level['interval'])) . '</strong>';
                         $results .= apply_filters('leaky_paywall_before_subscription_options_recurring_price', '');
                     } else {
                         $results .= '<strong>' . sprintf(__('%s%s %s', 'issuem-leaky-paywall'), $currencies[$currency]['symbol'], number_format($level['price'], 2), leaky_paywall_human_readable_interval($level['interval_count'], $level['interval'])) . '</strong>';
                         $results .= apply_filters('leaky_paywall_before_subscription_options_non_recurring_price', '');
                     }
                     if (!empty($level['trial_period'])) {
                         $results .= '<span class="leaky-paywall-trial-period">' . sprintf(__('Free for the first %s day(s)', 'issuem-leaky-paywall'), $level['trial_period']) . '</span>';
                     }
                 } else {
                     $results .= '<strong>' . __('Free', 'issuem-leaky-paywall') . '</strong>';
                 }
                 $results .= '</p>';
                 $results .= '</div>';
                 //Don't show payment options if the users is currently subscribed to this level
                 if (!in_array($level_id, $current_level_ids)) {
                     $results .= '<div class="leaky_paywall_subscription_payment_options">';
                     $results .= apply_filters('leaky_paywall_subscription_options_payment_options', $payment_options, $level, $level_id);
                     $results .= '</div>';
                 } else {
                     $results .= '<div class="leaky_paywall_subscription_current_level">';
                     $results .= __('Current Subscription', 'issuem-leaky-paywall');
                     $results .= '</div>';
                 }
                 $results .= '</div>';
             }
             $results .= '</div>';
             $results .= apply_filters('leaky_paywall_subscription_options_after_subscription_options', '');
             if ($has_allowed_value) {
                 $results .= '<div class="leaky_paywall_subscription_limit_details">';
                 $results .= '*' . ucfirst(leaky_paywall_human_readable_interval($settings['cookie_expiration'], $settings['cookie_expiration_interval']));
                 $results .= '</div>';
             }
         }
         $results .= apply_filters('leaky_paywall_subscription_options_footer', '');
     }
     return $results;
 }