/** * Save the post popup form */ function ajax_tp_saveEditPopup() { if (!current_user_can('edit_posts')) { die; } if (!wp_verify_nonce($_REQUEST['tinypass_nonce'], 'tinypass_options')) { die('Security check failed'); } tinypass_include(); $storage = new TPStorage(); $errors = array(); $ss = $storage->getSiteSettings(); $ps = $ss->validatePostSettings($_POST['tinypass'], $errors); $storage->savePostSettings($_POST['post_ID'], $ps); if (count($errors)) { echo "var a; tinypass.clearError(); "; foreach ($errors as $field => $msg) { echo "tinypass.doError('{$field}', \"{$msg}\");"; } die; } $ps = $storage->getPostSettings($_POST['post_ID']); echo tinypass_post_options_summary($ps); die; }
function tinypass_uninstall() { tinypass_include(); delete_option('tinypass_legacy'); $storage = new TPStorage(); $storage->deleteAll(); }
/** * Display the enable toggle on the page edit page */ function tinypass_page_options_display($post) { tinypass_include(); $storage = new TPStorage(); $ps = $storage->getPostSettings($post->ID); ?> <?php wp_nonce_field('tp-post-save-nonce', 'tp-post-save-nonce'); ?> <input type="checkbox" name="tinypass[enabled]" id="tp_page_enabled" <?php checked($ps->isEnabled()); ?> ><label for="tp_page_enabled"> Protect this page<label> <?php }
/** * This method determines if the tinypass-meter needs to be * embeded at the bottom of the page. * * If the post is tagged and the request is for a page then we will embed * * If the request is the home page it is embeded but not configured to track onLoad */ function tinypass_intercept_content($content) { global $tpmeter; global $post; tinypass_include(); $ss = tinypass_load_settings(); $storage = new TPStorage(); //Load the page $postSettings = null; if ($post->post_type == 'page') { $postSettings = $storage->getPostSettings($post->ID); } //or non-subscribers metered should be ignored $tpmeter->embed_meter = true; $pwOptions = $storage->getPaywall("pw_config"); if ($pwOptions->isDisabledForPriviledgesUsers() && is_user_logged_in() && current_user_can('edit_posts')) { $tpmeter->embed_meter = false; } //NOOP if pw is disabled or the wrong mode if ($pwOptions->isEnabled() == false || $pwOptions->isMode(TPPaySettings::MODE_METERED_LIGHT) == false) { return $content; } if (is_home()) { $tpmeter->track_page_view = $pwOptions->isTrackHomePage(); } else { if ($postSettings != null && $postSettings->isEnabled()) { $tpmeter->track_page_view = true; } else { //check if current post is tagged for restriction $post_terms = get_the_tags($post->ID); if ($post_terms) { foreach ($post_terms as $term) { if ($pwOptions->tagMatches($term->name)) { $tpmeter->track_page_view = true; break; } } } } } $tpmeter->paywall_id = $pwOptions->getPaywallID($ss->isProd()); $tpmeter->sandbox = $ss->isSand(); return $content; }
/** * Uupdate RID */ function ajax_tp_updateRID() { if (!current_user_can('edit_posts')) { die; } if (!wp_verify_nonce($_REQUEST['tinypass_nonce'], 'update_rid')) { die('Security check failed'); } tinypass_include(); $storage = new TPStorage(); $form = $_POST['tinypass']; $rid = $form['rid']; $ps = $storage->getPaywall($rid); if (isset($form['value']) && $form['value'] != '') { $value = $form['value']; $value = preg_replace('/[^0-9A-z]/', '', $value); $storage->updatePaywallRID($ps, $value); } echo "Saved"; die; }
<?php define('TINYPASS_FAVICON', 'http://www.tinypass.com/favicon.ico'); tinypass_include(); require_once dirname(__FILE__) . '/tinypass-mode-settings.php'; require_once dirname(__FILE__) . '/tinypass-site-settings.php'; require_once dirname(__FILE__) . '/tinypass-form.php'; require_once dirname(__FILE__) . '/tinypass-install.php'; require_once dirname(__FILE__) . '/tinypass-page-options.php'; add_action("admin_menu", 'tinypass_add_admin_pages'); function tinypass_add_admin_pages() { add_menu_page('Tinypass', 'Tinypass', 'manage_options', 'tinypass.php', 'tinypass_mode_settings', TINYPASS_FAVICON); add_submenu_page('tinypass.php', 'Paywall', 'Paywall', 'manage_options', 'tinypass.php', 'tinypass_mode_settings'); add_submenu_page('tinypass.php', 'General', 'General', 'manage_options', 'TinyPassSiteSettings', 'tinypass_site_settings'); } /* Adding scripts to admin pages */ add_action('admin_enqueue_scripts', 'tinypass_add_admin_scripts'); function tinypass_add_admin_scripts($hook) { if (preg_match('/TinyPass|tinypass/', $hook)) { wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui'); wp_enqueue_script('suggest'); wp_enqueue_script('tinypass_admin', TINYPASS_PLUGIN_PATH . '/js/tinypass_admin.js', array(), false, false); wp_enqueue_style('tinypass.css', TINYPASS_PLUGIN_PATH . '/css/tinypass.css'); } }
/** * This method performs nearly all of the TinyPass logic for when and how to protect content. * Based upon the TP configuration, the post, the tags this method will either permit access * to a post or it will truncate the content and show a 'purchase now' widget instead of the post content. * * Access is checked by retreiving an encrypted cookie that is stored after a successful purchase. * */ function tinypass_intercept_content($content) { global $tpstate; global $post; $tpstate->reset(); tinypass_include(); $ss = tinypass_load_settings(); //break out if Tinypass is disabled if ($ss->isEnabled() == false) { return $content; } $storage = new TPStorage(); $postOptions = $storage->getPostSettings($post->ID); $tagOptions = $storage->getPaywallByTag($ss, $post->ID); if ($tagOptions->isEnabled() == false) { $tagOptions = $storage->getPaywallSubRefID($ss, $post->ID); } TinyPass::$AID = $ss->getAID(); TinyPass::$PRIVATE_KEY = $ss->getSecretKey(); TinyPass::$SANDBOX = $ss->isSand(); //TinyPass::$API_ENDPOINT_DEV = 'http://tinydev.com:9000'; $store = new TPAccessTokenStore(); $store->loadTokensFromCookie($_COOKIE); //we want to dump the button on this page if ($tagOptions->getSubscriptionPageRef() == $post->ID) { $tagOffer = TPPaySettings::create_offer($tagOptions, $tagOptions->getResourceId()); $gotolink = get_page_link($tagOptions->getSubscriptionPageSuccessRef()); $req = new TPPurchaseRequest($tagOffer); $req->setCallback('tinypass_redirect'); $button1 = $req->generateTag(); $tpstate->add_scripts = true; if (preg_match('/\\[tinypass\\s+rid.*\\]/', $content)) { $content = preg_replace('/\\[tinypass\\srid+.*\\]/', $button1, $content); $button1 = ''; } else { $button1 = "<div id='tinypass_subscription_holder'>{$button1}</div>"; } return $content . $button1 . "<script>" . "var tp_goto = '{$gotolink}';" . "if(typeof tinypass_redirect != 'function') {\n\t\t\t\t\t\t\t\tfunction tinypass_redirect(status){\n\t\t\t\t\t\t\t\tif(status.state == 'granted'){\n\t\t\t\t\t\t\t\t\twindow.location = tp_goto;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(typeof tpOnPrepare != 'function') {\n\t\t\t\t\t\t\tfunction tpOnPrepare(status){\n\t\t\t\t\t\t\t\tif(status.state == 'granted'){\n\t\t\t\t\t\t\t\t\t//window.location = tp_goto;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}" . "</script>"; } //exit if everything is disabled if ($postOptions->isEnabled_20() == false && $tagOptions->isEnabled() == false) { return $content; } $tpstate->add_scripts = true; //When content is shown in list form, i.e. categories we still need to truncate content //At this point in the execution we know that TP is enabled so we have to protect if (is_singular() == false) { $c = get_extended_with_tpmore($content); if ($c['extended'] == '') { $content = tinypass_trim_excerpt($content); } else { $content = $c['main']; } return $content; } define('DONOTCACHEPAGE', true); define('DONOTCACHEDB', true); define('DONOTMINIFY', true); define('DONOTCDN', true); define('DONOTCACHCEOBJECT', true); $postOffer = null; $tagOffer = null; $postToken = null; $tagToken = null; if ($postOptions->isEnabled_20() && $ss->isPPPEnabled()) { $postOffer = TPPaySettings::create_offer($postOptions, "wp_post_" . strval($post->ID), $postOptions->getResourceName() == '' ? $post->post_title : $postOptions->getResourceName()); $postToken = $store->getAccessToken($postOffer->getResource()->getRID()); } $tagOfferTrialActive = FALSE; if ($tagOptions != null && $tagOptions->isEnabled()) { $tagOffer = TPPaySettings::create_offer($tagOptions, $tagOptions->getResourceId()); $tagToken = $store->findActiveToken('/' . $tagOptions->getResourceId() . '/'); } //For PPV mode if ($tagOptions->isMode(TPPaySettings::MODE_PPV) && $tagOptions->isEnabled()) { $rid = "wp_post_" . strval($post->ID); $tagOffer = TPPaySettings::create_offer($tagOptions, $rid, $post->post_title); //If a offer on the post is defined then use that one if ($postOffer != null) { $tagOffer = null; } $tagToken = $store->getAccessToken($rid); } else { if ($tagOptions->isMode(TPPaySettings::MODE_METERED) && $tagOptions->isEnabled()) { //Only check metered if the mode is metered and it is enabled $meter = null; if ($tagOptions->isMetered()) { $cookieName = "tr_" . substr(md5($tagOptions->getResourceId()), 0, 20); $meter = TPMeterHelper::loadMeterFromCookie($cookieName, $_COOKIE); $lockoutPeriod = $tagOptions->getMeterLockoutPeriodFull(); if ($meter == null) { $meter = TPMeterHelper::createViewBased($cookieName, $tagOptions->getMeterMaxAccessAttempts(), $lockoutPeriod); } $lockoutPeriodEndTime = time() + TPUtils::parseLoosePeriodInSecs($lockoutPeriod); $meter->increment(); setcookie($cookieName, TPMeterHelper::__generateLocalToken($cookieName, $meter), $lockoutPeriodEndTime, '/'); if ($meter->isTrialPeriodActive()) { $tagOfferTrialActive = TRUE; if ($tagOptions->isCounterEnabled() && $meter->getTrialViewCount() > $tagOptions->getCounterDelay(PHP_INT_MAX)) { $tpstate->show_counter = true; $onclick = 'onclick="return false"'; if ($tagOptions->isCounterOnClick(TPPaySettings::CT_ONCLICK_PAGE)) { $gotolink = get_page_link($tagOptions->getSubscriptionPageRef()); $onclick = 'href="' . $gotolink . '"'; } else { if ($tagOptions->isCounterOnClick(TPPaySettings::CT_ONCLICK_APPEAL)) { $onclick = 'onclick="tinypass.showAppeal(); return false"'; $tpstate->embed_appeal = __tinypass_create_appeal($tagOptions); } } $tpstate->counter = __tinypass_render_template(TINYPASS_COUNTER_TEMPLATE, array('count' => $meter->getTrialViewCount(), 'max' => $meter->getTrialViewLimit(), 'remaining' => $meter->getTrialViewLimit() - $meter->getTrialViewCount(), 'position' => 'position-' . $tagOptions->getCounterPosition(), 'onclick' => $onclick)); } if ($tagOptions->getAppealEnabled() && $meter != null) { $count = $meter->getTrialViewCount(); if ($count == $tagOptions->getAppealNumViews() || $count > $tagOptions->getAppealNumViews() && $count % $tagOptions->getAppealFrequency() == 0) { $tpstate->show_appeal = true; $tpstate->embed_appeal = __tinypass_create_appeal($tagOptions); } } return $content; } } } } if ($postOffer == null && $tagOffer == null) { return $content; } //If they already have access to the post if ($postToken != null && $postToken->isAccessGranted()) { return $content; } //If the tag level offer does not exist or access is already granted if ($tagToken != null && $tagToken->isAccessGranted() || $tagOfferTrialActive) { return $content; } $c = get_extended_with_tpmore($post->post_content); if ($c['extended'] == '') { //means there was no <!--more--> defined $content = tinypass_trim_excerpt($content); } else { $content = $c['main']; } if ($ss->isDisableCommentsWhenDenied()) { add_filter('comments_open', 'tinypass_close_comments', 1000); $post->comment_status = "closed"; add_filter('comments_template', 'tinypass_skip_comments'); } /* * Construct the offers for both the tag level offer and the post level offer if they exist */ $ticketoptions = array(); if ($postOffer) { $req = new TPPurchaseRequest($postOffer, $ticketoptions); $tpstate->post_req = array('req' => $req, 'message1' => $postOptions->getDeniedMessage1("") != "" ? $postOptions->getDeniedMessage1() : $ss->getDeniedMessage1(), 'sub1' => $postOptions->getDeniedSub1("") != "" ? $postOptions->getDeniedSub1() : $ss->getDeniedSub1()); $req->setCallback('tinypass_reloader'); } if ($tagOffer) { $req2 = new TPPurchaseRequest($tagOffer, $ticketoptions); $tpstate->tag_req = array('req' => $req2, 'message1' => $tagOptions->getDeniedMessage1(), 'sub1' => $tagOptions->getDeniedSub1()); $req2->setCallback('tinypass_reloader'); } //Switch the offer order if selected in the settings if ($tagOptions->isPostFirstInOrder() == false) { $temp = $tpstate->post_req; $tpstate->post_req = $tpstate->tag_req; $tpstate->tag_req = $temp; } return $content; }